struts中指定编码(使用Filter后仍然乱码)

https://www.cnblogs.com/oldinaction/p/5167481.html

概述:

  Tomcat默认是 ISO编码,不支持中文。尝试过自己写 Filter,在web.xml中将自己写的FIlter放在最前面(否则不会执行Filter中的doFilter方法),甚至也在tomcat配置文件 server.xml中 的 Connector也添加了 URIEncoding="utf-8",以及在 eclipse中的properties也设置了 同样的编码方式,之后 通过在 struts.xml 中添加 

1 <constant name="struts.i18n.encoding" value="utf-8"></constant>
View Code

也还是乱码。

最后,在 web.xml 中 的struts的filter添加(蓝色部分) 

<filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>struts.i18n.encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>  
    </filter>  

解决了问题。 我猜想,应该跟struts自己指定了编码有关。

 

posted @ 2017-12-30 15:24  wonkju  阅读(166)  评论(0编辑  收藏  举报