Strings2=newString(s1.getBytes(“ISO-8859-1”),”GBK”);
%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%
%
request.setCharacterEncoding("UTF-8");
%
◆charset=UTF-8的作用是指定JSP向客户端输出的编码方式为“UTF-8”;
◆pageEncoding="UTF-8",为了让JSP引擎能正确地解码含有中文字符的JSP页面,这在LINUX中很有效;
◆request.setCharacterEncoding("UTF-8");是对请求进行了中文编码。
有时,这样仍不能解决问题,还需要这样处理一下:
Stringmsg=request.getParameter("message");
Stringstr=newString(msg.getBytes("ISO-8859-1"),"UTF-8");
out.println(st);
2、Tomcat5.5中文乱码
只要把%TOMCAT安装目录%/webapps\servlets-examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.class文件拷到你的webapp目录/filters下,如果没有filters目录,就创建一个。
2)在你的web.xml里加入如下几行:
filter
filter-name SetCharacterEncoding /filter-name
filter-class filters.SetCharacterEncodingFilter /filter-class
init-param
param-name encoding /param-name
param-value GBK /param-value
/init-param
/filter
filter-mapping
filter-name SetCharacterEncoding /filter-name
url-pattern /* /url-pattern
/filter-mapping
2、get方式的解决办法
1)打开tomcat的server.xml文件,找到区块,加入如下一行:
CONNECTOR NBSP; NBSP; NBSP; NBSP;
port="80"maxThreads="150"minSpareThreads="25"maxSpareThreads="75"
enableLookups="false"redirectPort="8443"acceptCount="100"
debug="0"connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="GBK"
/
functionaddFracasReport(){
varurl="controler?actionId=0_06_03_01 actionFlag=0010";
varurlmsg=" reportId="+fracasReport1.textReportId.value;//故障报告表编号
varxmlHttp=Common.createXMLHttpRequest();
xmlHttp.onreadystatechange=Common.getReadyStateHandler(xmlHttp,
eval("turnAnalyPage"));
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type","
application/x-www-form-urlencoded);
xmlHttp.send(urlmsg);
}