第一次修改有问题是因为IE不知当前当前页面的编码方式,用了西文,当第二次用同样页面的,会自动纠正一次,所以以后都不会出现乱码问题了.<%@ page contentType="text/html;charset=GB2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
以上两条若解决不了,可用以下函数处理一次先:
public String FormatConvert(String from)
{ try{
byte[] b = from.getBytes("iso8859-1");
return new String(b,"gb2312");
}catch(Exception e){}
return null;
}
good luck!
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
以上两条若解决不了,可用以下函数处理一次先:
public String FormatConvert(String from)
{ try{
byte[] b = from.getBytes("iso8859-1");
return new String(b,"gb2312");
}catch(Exception e){}
return null;
}
good luck!
得到的是中文,试一下<a href="orther.jsp?strTemp=<%=URLEncoder.encode(strTemp)%>"></a>
引入<%@page import="java.net.*"%>
你换成TOMCAT4试试
如果是WebSphere就不需要考虑这些问题了。
String s =
new String(request.getParameter("s").getBytes("ISO-8859-1"),
"GB2312");
return new String(ss.getBytes("ISO8859_1"));
}
export LC_ALL=zh_CN.gb2312
export LANG=zh_CN.gb2312针对要处理中文的jsp页面,设置java使用的unicode代码页
<%@ page contentType="text/html;charset=GB2312" %>针对ie显示,指定使用中文现实文字内容
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">从url或post取得参数后转换为中文页的unicode:
String a = request.Parameter("aaa");
byte[] tempb = a.getBytes("ISO8859_1");
a = new String(tempb);就这些了
public String valueOf(String Source) throws Exception
{
if(Source == null)
return ""; byte[] temp = Source.getBytes("8859_1");
String query = new String(temp, "GB2312");
return query;
}
/*
使用时:
out.print(对象名.valueOf(strTemp));
就可以了,保证没有问题,我用过N次了!
*/
jsp是在你的app svr的平台上编译的,编译用的encoding是javac 自动取平台字符集的。
其次,数据库的字符集编码也很重要,如果也是中文的,数据表里的存储也是按照中文字符集的。
第三,jsp里的<% page charset="" %>也要正确设置。
只有这三个字符集是一致的,才能正确显示。
我通常的做法是,全部用西文字符集,在jsp中不需charset设置。
把收到的String-->byte[] 然后把byte[]编码成特殊的stinrg
如-12|33|443|88|
接收时再反着来,肯定没问题的.
我以前碰到的字符问题都是这样解决的。
表示是中国地区的编码
是在jsp页面的顶部写上 code=936 吗?怎么写啊,麻烦给予实例。
谢谢!!