struts中指定編碼(使用Filter後仍然亂碼)

http://www.javashuo.com/article/p-vskxndiy-ez.htmlhtml

概述:web

  Tomcat默認是 ISO編碼,不支持中文。嘗試過本身寫 Filter,在web.xml中將本身寫的FIlter放在最前面(不然不會執行Filter中的doFilter方法),甚至也在tomcat配置文件 server.xml中 的 Connector也添加了 URIEncoding="utf-8",以及在 eclipse中的properties也設置了 一樣的編碼方式,以後 經過在 struts.xml 中添加 apache

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

也仍是亂碼。tomcat

最後,在 web.xml 中 的struts的filter添加(藍色部分) eclipse

<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本身指定了編碼有關。ide

相關文章
相關標籤/搜索