老题新问:中文编码转换 wuwu,怎么没人回呢,是不是我写的不够明白阿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String s2="\\u"+ Integer.toHexString((int)bytes[0]) +Integer.toHexString((int)bytes[1]);应改成 String s2= new String(bytes,"GBK"); 就OK了!试试看! 针对jsp和servlet:解决办法:第一:在jsp页面加入:<%@ page contentType="text/html; charset=gb2312" %>或者在servlet里面 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=gb2312");//这是重要的上面的如果在不行就用如下的方法在数据入库前进行调用:public static String UnicodeToChinese(String s){ try{ if(s==null||s.equals("")) return ""; String newstring=null; newstring=new String(s.getBytes("ISO8859_1"),"gb2312"); return newstring; } catch(UnsupportedEncodingException e) { return s; } }public static String ChineseToUnicode(String s){ try{ if(s==null||s.equals("")) return ""; String newstring=null; newstring=new String(s.getBytes("gb2312"),"ISO8859_1"); return newstring; } catch(UnsupportedEncodingException e) { return s; } }3:)解决weblogic/webshpere中文问题:在web.xml文件中需要配置中文环境。r如下:<context-param> <param-name>weblogic.httpd.inputCharset./*</param-name> <param-value>GB2312</param-value></context-param> 你换算错了,应该是:byte bytes[]={-61,-15}; 楼主,你搞错了吧民转换为byte数组应该是-61 -15阿,你使用 byte al[] = s1.getBytes(); for(int i=0;i<al.length;i++) { System.out.println(al[i]); }输出看看就知道了至于转换,使用楼上即可,不过最好使用"GB2312" unicode码并不是字节码,将6c11做为字节码是不对的 Spring+Struts整合找不到指定的Action方法? jbuilder 导入 api 如果JAVA死了,那谁将取代JAVA的地位? 匿名SMTP服务器研究 在jtextPane中鼠标右键无法改变jtextpane的caretposition(急) 请问谁有JAVA2核心技术 卷1 的源代码啊!~! 如何查看我安装了哪些JDBC驱动程序? odbc:jdbc桥是不是也有安装驱动? 请问一个最简单的问题! JB7怎么将CLASS打包成EXE文件? 文本框的问题 使用jdk1.4+wstk3.2+tomcat+axis进行开发webservice 如何用java连接mysql数据库?
应改成
String s2= new String(bytes,"GBK");
就OK了!试试看!
解决办法:
第一:
在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");//这是重要的
上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}3:)解决weblogic/webshpere中文问题:
在web.xml文件中需要配置中文环境。r如下:
<context-param>
<param-name>weblogic.httpd.inputCharset./*</param-name>
<param-value>GB2312</param-value>
</context-param>
民转换为byte数组应该是-61 -15阿,你使用
byte al[] = s1.getBytes();
for(int i=0;i<al.length;i++) {
System.out.println(al[i]);
}
输出看看就知道了
至于转换,使用楼上即可,不过最好使用"GB2312"