每个jsp页面开头都要加下面一句:
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage="" %>
另外一种方法:
步骤1:添加过滤器
在TOMCAT中找到这2个文件RequestDumperFilter.java,SetCharacterEncodingFilter.java,他们位于 \webapps\examples\WEB-INF\classes\filters目录,加到你的工程文件里去,编译他们。
步骤2:配置WEB.XML
在web.xml里加入这一段
……
<filter>
<filter-name>Set Character Encoding</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>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
步骤3:修改server.xml
在server.xml修改2个地方
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding='GBK'/>
<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='GBK'/>
以上的GBK也可以改成GB2312