web.xml some useful configuration

1. A very simple and practical filter of spring. When different character sets are used for encoding in the current JSP page and JAVA code, there will be garbled characters in the data submitted by the form or when uploading/ downloading Chinese name files. This filter can be added.

<filter>  
	<filter-name>CharacterEncodingFilter</filter-name>  
	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
	<init-param>  
		<param-name>encoding</param-name>  
		<param-value>utf-8</param-value>  
	</init-param>  
	<init-param>  
		<param-name>forceEncoding</param-name>  
		<param-value>true</param-value>  
	</init-param>  
</filter>  
<filter-mapping>  
	<filter-name>CharacterEncodingFilter</filter-name>  
	<url-pattern>*.do</url-pattern>  
</filter-mapping>

    encoding-----> is used to specify a specific character set
    forceEncoding-------> In earlier versions of Spring, this parameter has a very single function. When a character set has been specified in the request, it will be used again. The character set corresponding to endcoding is set to the request. For example, if the filter is configured in web.xml as above, when the request is submitted, the filter will determine whether request.getCharacterEncoding() is null, and if it is null, the request will be made. The operation of setCharacterEncoding("UTF-8"), if not null then the filter will do nothing.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326945474&siteId=291194637