救命啊--中文问题;BEAN与JSP中正常;但SERVLET中不行!!!!!!! String abc = new String(aa.getBytes("ISO-8859-1"),"GB2312");试试看!中文的编码我有点忘了!可能是这样的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 编译所有的servlet都加参数,用命令javac testServlet.java -encoding 8859_1在servlet中的中文转码,用new String(s.getBytes("8859_1"),"gb2312")当然,还要设置头信息response.setContentType("text/html;charset=gb2312"); 楼上的对!这是servlet从页面上取字时编码在搞鬼吧? 同意楼上,不外乎是这两种转换:String temp=new String(temp_p.getBytes("ISO8859-1"),"GB2312");String temp=new String(temp_p.getBytes("GB2312"),"ISO8859-1"); 3:)针对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; } } db2自定义函数的问题 希望帮忙看下 Apache和Tomcat版本问题 还是动态包含include的问题 axis2 客户端调用,如何去掉自动产生的namespace部分 急求JS高手帮忙解决一个问题 jsp网站发布问题 oracle.sql.CLOB clobtt 的定义问题 120寻救!中文乱码和暴露源码???? 有没有那位高手做过发信部分的,怎么按照数据库中的email地址,发信呢??? java 数据库分库 关于在JSP中调用JAVABEAN的问题(50分相赠) 问题?
用命令javac testServlet.java -encoding 8859_1在servlet中的中文转码,用new String(s.getBytes("8859_1"),"gb2312")当然,还要设置头信息
response.setContentType("text/html;charset=gb2312");
String temp=new String(temp_p.getBytes("ISO8859-1"),"GB2312");
String temp=new String(temp_p.getBytes("GB2312"),"ISO8859-1");
解决办法:
第一:
在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;
}
}