论坛首页 Java企业应用论坛

关于socket连接weblogic中文乱码的问题请教

浏览 3833 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-09-30  
最近做一个项目需要使用socket连接weblogic收发报文,encode都是按照标准设置好了,都设置为utf-8的格式,但是发送到weblogic端的servlet上时接收的中文还是乱码。
同样的程序,发送到tomcat上的servlet就是正常的中文。
哪位有过相关经验的给指教一下啊,多谢!


附:相关部分代码

客户端:
tSocket = new Socket("IP","PORT");
String tHttpHeader = "POST " + MerchantConfig.getTrustPayTrxURL() + " HTTP/1.1" + MerchantConfig.getTrustPayNewLine() +
"Content-Type: application/x-www-form-urlencoded" + MerchantConfig.getTrustPayNewLine() +
"Host: " + MerchantConfig.getTrustPayServerName() + ":" + MerchantConfig.getTrustPayServerPort() + MerchantConfig.getTrustPayNewLine() +
"Accept: text/html, image/gif, image/jpeg, *; q=.2, * /*; q=.2" + MerchantConfig.getTrustPayNewLine() +
"Accept-Charset: utf-8" + MerchantConfig.getTrustPayNewLine() +
"Connection: keep-alive" + MerchantConfig.getTrustPayNewLine() +
"Content-Length: ";
System.out.println("tHttpHeader:" + tHttpHeader);

//PrintWriter tOut = new PrintWriter(tSocket.getOutputStream(),true);
PrintWriter tOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(tSocket.getOutputStream(), "utf-8")));
String test = new String("测试");
String tHttpRequest = tHttpHeader + tContentLength + MerchantConfig.getTrustPayNewLine() + MerchantConfig.getTrustPayNewLine() + test;
System.out.println("tHttpRequest:" + tHttpRequest);
tOut.print(tHttpRequest);
tOut.flush();

服务端:
request.setCharacterEncoding(“utf-8”);
requestMsg = getRequestMessage(request);
System.out.println("requestMsg:" + requestMsg);
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics