我想,你在JSP中也应该对字符进行转换一次吧
public static String toGB2312(String str) {
if (str == null) {
return null;
}
try {
return new String(str.getBytes("ISO8859_1"), "gb2312");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
public static String toGB2312(String str) {
if (str == null) {
return null;
}
try {
return new String(str.getBytes("ISO8859_1"), "gb2312");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
<%@page contentType="text/html;charSet=gb2312"%>
<%request.setCharacterEncoding("GB2312");%>
做一个字符集filter(可以直接用tomcat的那个)
改你的应用中web.xml文件,将字符filter的值设为utf-8做上述工作后,绝大部分乱码问题都可克服,不知对你的这种情况是否有帮助。
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.io.*"%>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<%
out.println(trans(request.getParameter("name")));
%>
然后后面要把ISO8859-1转为GB2312