- 締切済み
サーブレットで文字化け
サーバ Fedora Core 6 / tomcat5.5 クライアントもFedoraなら文字化けしません。 ウィンドウズxpから接続すると文字化けします。 アプレットのプログラムで送信する関数のみ抜粋した。引数sが送信する文字列でこれが文字化けします。送信した変数sをJLabelで表示するとウィンドウズでも文字化けしてなかった。そしてサーバー側のログは文字化けしていたのですが原因がわかりません。どうしたらいいですか? //■アプレット側 文字列送信用関数 public void send(String s) { try { sock = new Socket(サーバのIPアドレス,9999); //■サーバーに接続 fin = sock.getInputStream(); fout = sock.getOutputStream(); ffin = new InputStreamReader(fin); in = new BufferedReader(ffin); out = new PrintWriter(fout,true); out.println("POST / HTTP/1.1"); out.println("Accept: */* "); out.println("Accept-Language: ja"); out.println("Accept-Encoding: gzip,deflate"); out.println("User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); out.println("Host: "+getParameter("ipAddress")); out.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8"); out.println("Content-Length: "+(s.getBytes("UTF-8").length)); out.println("Connection: Keep-Alive"); out.println(""); out.println(s); } catch(IOException e) { } } サーバー側 変数sの表示 public void service(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException { //■通信関係 PrintWriter out; BufferedReader in; //■入力した文字列 String st,str; try { //■通信開始 in = new BufferedReader(new InputStreamReader(req.getInputStream())); out = new PrintWriter(res.getOutputStream(),true); //■文字列読み込み st = in.readLine(); str = new String(st.getBytes("UTF-8")); System.out.println("受信した文字列"+str);
- みんなの回答 (2)
- 専門家の回答
補足
どうしたらいいですか? どこを変えればいいですか? どの部分をどうかえればいいですか?