java中文乱码解决方案

struts2中文乱码解决方法

 

 

1. 在struts2里面,最好将所有字符都设成utf-8。 <%@ page contentType="text/html; charset=UTF-8"%> <%@ page pageEncoding="UTF-8" %>1.1 在jsp页面设定字符编码。这边有必有说明的是如果是jsp+java bean+servlet的方案,中文乱码很好解决,统一设成gb2312就可以了。 1.2 使用struts框架字符集不能设成gb2312,要改成utf-8。

 2. 在struts.properties 添加:

struts.devMode=false struts.enable.DynamicMethodInvocation=true struts.i18n.reload=true struts.ui.theme=simple

struts.locale=zh_CN struts.i18n.encoding=UTF-8

struts.serve.static.browserCache=false struts.url.includeParams=none

其中locale、encoding就是字符集的设定了。

3. 在web.xml加个filter

  <!-- zh-cn encoding --> <filter> <filter-name>struts-cleanup </filter-name> <filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp </filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup </filter-name> <url-pattern>/* </url-pattern> </filter-mapping>

posted @ 2011-11-14 14:03  hezheqin  阅读(119)  评论(0编辑  收藏  举报