解决中文乱码用spring经典编码过滤器org.springframework.web.filter.CharacterEncodingFilter

使用spring的前提下在web.xml中配置
<filter>
<filter-name>encodingFilter </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-mapping>
<filter-name>encodingFilter </filter-name>
<url-pattern>*.do </url-pattern>
</filter-mapping>

千万要注意他们了的先后顺序,顺序颠倒了就不管用了哦

 

你可能感兴趣的:(spring,filter)