帮我看看这段代码,非内码高手勿入!

offsider 2002-04-22 04:26:01
public class execute(httpsession,httprequest,httpresponse)
{
...........

httpurlconnection.connect();
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(httpurlconnection.getOutputStream());
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
bufferedwriter.write(String.valueOf(String.valueOf(s4)).concat("\r\n"));
bufferedwriter.flush();
bufferedwriter.close();
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream()));
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
for(String s11 = null; (s11 = bufferedreader.readLine()) != null;)
{
s11 = s11.trim();
String s11 = String.valueOf(String.valueOf(s11)).concat("\n");
//Date d = new Date();
//String temp = "测试"+d.toString();
bytearrayoutputstream.write(s11.getBytes("GB2312"));
bytearrayoutputstream.write(temp.getBytes());
//}

bufferedreader.close();
httpurlconnection.disconnect();
String s12 = new String(bytearrayoutputstream.toByteArray());
session.setAttribute("bufferedChat", s12);

.............

}


在jsp程序中调用,
String tempThechat = URLEncoder.encode((String)session.getValue("bufferedChat")).replace('+',' ');
<script language="JavaScript"><!--
var thechat = '<%= tempThechat%>';
function execute()
{
if (typeof(self.parent.dbcontent) != "undefined")
{
self.parent.dbcontent.document.open("text/html");
self.parent.dbcontent.document.writeln(unescape(thechat));
self.parent.dbcontent.document.write();
self.parent.dbcontent.document.close();
}
}
//--></script>

这是一个聊天室程序,写出来的中文全是乱码,请问那位高手能解决?马上给分!
...全文
23 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhu_liping 2002-04-24
  • 打赏
  • 举报
回复
就这个呀,
hehe,
你很讨人厌哟?!
xue_sharp 2002-04-24
  • 打赏
  • 举报
回复
很普通的中文问题啊,随便搜索一下就很多。

说的挺吓人的,偶都不敢看,因为偶不是高手
huyuefox 2002-04-24
  • 打赏
  • 举报
回复
传递参数是中文时,我用getBytes("GB2312")。
donny2000 2002-04-22
  • 打赏
  • 举报
回复
public String Ascii2Chinese(String s) {
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (byte)(orig[i]&0xFF);
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("GB2312");
return new String(toChar.convertAll(dest));
}
catch (Exception e) {
System.out.println(e);
return s;
}
}

public static String Chinese2Ascii(String s) {
try {
CharToByteConverter toByte = CharToByteConverter.getConverter("GB2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}


这两个方法试试 记得加载 sun.io.*
salute 2002-04-22
  • 打赏
  • 举报
回复
你不是说勿入嘛,大家都很谦虚!:-)
offsider 2002-04-22
  • 打赏
  • 举报
回复
为什么没人理我啊?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧