在TOMCAT的EXAMPLE里面有源代码,SetCharacterEncodingFilter.class,
(%TOMCAT_HOME%/webapps/examples/WEB-INF/classes/filters)
需要拷贝到WEB-INF/classes/filters里面,可以完整目录拷贝
------------------------------------------------------------------
修改%TOMCAT_HOME%/conf/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>
------------------------------------------------------------------
修改:
%TOMCAT_HOME%/conf/server.xml 在
<Connector..... 的最后加入
URIEncoding="GBK"
------------------------------------------------------------------
如果要让 manage 一样起作用,建立
%TOMCAT_HOME%/server/webapps/manager/WEB-INF/classes 目录
将 filter 目录拷贝进去
------------------------------------------------------------------
以后每次建立一个 servlet 程序都要将 filter 目录拷贝到 WEB-INF/classes
下面才行,如果在调试的时候出现一些错误,可能就是由于它没有拷贝过来
完毕后重新启动 TomCat