进行以下编码就可以了
String s=request.getParameter("name");
s=new String(s.getBytes("ISO8859_1"),"gb2312");
String s=request.getParameter("name");
s=new String(s.getBytes("ISO8859_1"),"gb2312");
解决方案 »
- 关于spring 的security启动报错
- 第一个javabean,有问题,请求解答..
- 小弟请教java专家 : java代码转译成pb问题
- tomcat配置https ,,能不能只把某一个应用配置为HTTPS,,,其他应用还是http
- 天气预报
- *急!急!tomcat配置问题?
- 如何将客户端的图片上传到服务器
- 难道<textarea>里不能实现单段的缩进?请讨论!
- 同一web server 下发布的不同web application,怎样使他们之间的session 对象可互访?
- resin 小问题
- JikLiu(小铃铛), nxxld (ForJava) 混的不错嘛,都四个三角了,讲解还贼详细,要不要进来解释一下
- 怎样将tomcat4.0发布成windows的一个NT service
byte[] sbyte=s.getBytes("ISO8859_1");
s=new String(sbyte);或者strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK"); 例: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;
}
}
从JSP的FORM中提取的汉字出现乱码的话, content type 设为ISO8859_1,就没问题了.这两个是个矛盾,因此我解决的办法就是
(1) content type设为ISO8859_1
(2) 在Servlet的out.print尽量不用中文.
(3) 如果必须用中文,则自已写个bean,里面设一些静态的中文字符串,需要的时候直接调用.