码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-30 17:02:17      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:.com   ons   exec   struts   图片   www   target   分享图片   分享   

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自己指定了编码有关。

 

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

标签:.com   ons   exec   struts   图片   www   target   分享图片   分享   

原文地址:https://www.cnblogs.com/listened/p/8150020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!