Posted on 2010-03-24 10:55
祝嘉 阅读(797)
评论(0) 编辑 收藏 所属分类:
JSP
首先是get方式提交乱码,修改tomcat的server.xml。在Connector节点添加URIEncoding="UTF-8"
1<Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
然后是post方式提交乱码,tomcat中提供了一个filter用于修改request的编码。
文件目录是apache-tomcat-6.0.20\webapps\examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java
在web.xml中配置过滤器指定编码
Web
1 <filter>
2 <filter-name>SetCharacterEncodingFilter</filter-name>
3 <filter-class>filters.SetCharacterEncodingFilter</filter-class>
4 <init-param>
5 <param-name>encoding</param-name>
6 <param-value>utf-8</param-value>
7 </init-param>
8 </filter>
9 <filter-mapping>
10 <filter-name>SetCharacterEncodingFilter</filter-name>
11 <url-pattern>/*</url-pattern>
12 </filter-mapping>