<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 要过滤得类型 -->
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
</web-app>
public class CharacterEncodingFilterextends OncePerRequestFilter
Servlet 2.3/2.4 Filter that allows one to specify a character encoding for requests. This is useful because current browsers typically do not set a character encoding even if specified in the HTML page or form.
This filter can either apply its encoding if the request does not already specify an encoding, or enforce this filter's encoding in any case ("forceEncoding"="true"). In the latter case, the encoding will also be applied as default response encoding on Servlet 2.4+ containers (although this will usually be overridden by a full content type set in the view).
本文介绍了一个Spring框架中的字符编码过滤器,该过滤器允许开发者为请求指定字符编码,以解决浏览器通常不设置字符编码的问题。文章详细展示了如何配置web.xml中的CharacterEncodingFilter,并解释了其工作原理。

被折叠的 条评论
为什么被折叠?



