当前位置: 技术问答>java相关
帮我看看这段代码,非内码高手勿入!
来源: 互联网 发布时间:2015-05-15
本文导语: public class execute(httpsession,httprequest,httpresponse) { ........... httpurlconnection.connect(); OutputStreamWriter outputstreamwriter = new OutputStreamWriter(httpurlconnection.getOutputStream()); BufferedWriter bufferedwriter = new Buffere...
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("rn"));
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('+',' ');
这是一个聊天室程序,写出来的中文全是乱码,请问那位高手能解决?马上给分!
{
...........
httpurlconnection.connect();
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(httpurlconnection.getOutputStream());
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
bufferedwriter.write(String.valueOf(String.valueOf(s4)).concat("rn"));
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('+',' ');
这是一个聊天室程序,写出来的中文全是乱码,请问那位高手能解决?马上给分!
|
public String Ascii2Chinese(String s) {
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for (int i=0;i