日期:2014-05-18  浏览次数:20826 次

过滤器设置编码无效,依然乱码
郁闷了。

必须在设置request编码方式后加一句request.getParameter才能生效

过滤器代码片断:
protected   void   doFilterInternal(
HttpServletRequest   request,   HttpServletResponse   response,   FilterChain   filterChain)
throws   ServletException,   IOException   {

if   (this.forceEncoding   ||   request.getCharacterEncoding()   ==   null)   {

request.setCharacterEncoding(this.encoding);
request.getParameter( "mm ");//加上这句话就一切正常了,否则乱码
}
filterChain.doFilter(request,   response);
}
-------------------------------------------
web.xml

<filter>
<filter-name> encodingFilter </filter-name>
<filter-class> cn.edu.njtu.mofan.common.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> encodingFilter </filter-name>
<url-pattern> *.page </url-pattern>
</filter-mapping>


请教,有没有人遇到过相似的情况。另外可能的原因是什么。谢谢

------解决方案--------------------
过滤器偶也是刚刚开始学~一起学习~
------解决方案--------------------
關注一下縣