方法一:new String(request.getParameter("test").getBytes("iso-8859-1"),"GBK")
方法二:
1、
在jsp中加入下面两行
<%@ page contentType="text/html; charset=GBK" language="java" %>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
2、
在TOMCAT中找到SetCharacterEncodingFilter.java,他们位于D:\Tomcat5.0.27\webapps\jsp-examples\WEB-INF\classes\filters,加到你的工程文件里去,并修改包名。
3、
配置WEB.XML,在web.xml里加入这一段
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>utils.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4、修改server.xml中两个部分
<Connector port="8090"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding='GB2312'/>
<Connector className="org.apache.coyote.tomcat5.CoyoteConnector"
port="8009" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="0"
useURIValidationHack="false" protocol="AJP/1.3"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
URIEncoding='GB2312'/>