用struts开发时,遇上汉字乱码问题.有资料说,将struts源码的action类,加转码,就可以解决.加了后,在jsp与action交互时,汉字问题解决了.但,不走这个类的其它汉字,如resorce里,用本地化汉字的时候,message出来,在jsp里是乱码.
网上还有说在web.xml里,设置web应用的字符集,但我没有设置成功.如何设置,能根本解决乱码问题呢.多谢!
------解决方案--------------------
http://community.csdn.net/Expert/TopicView3.asp?id=5269635
------解决方案--------------------
1.所有页面都定义
<%@ page language= "java " contentType= "text/html;charset=UTF-8 " %>
2.配置Servelet的过滤器
public class SetCharacterEncodingFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException {
request.setCharacterEncoding( "UTF-8 ");
// 传递控制到下一个过滤器
chain.doFilter(request, response);
}
}
配置web.xml
<filter>
<filter-name> Set Character Encoding </filter-name>
<filter-class> SetCharacterEncodingFilter </filter-class>
</filter>
<filter-mapping>
<filter-name> Set Character Encoding </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>
3.打开tomcat的server.xml文件,找到区块,加入如下一行:
URIEncoding= "UTF-8 "
完整的应如下:
<Connector port= "8080 " maxThreads= "150 " minSpareThreads= "25 " maxSpareThreads= "75 " enableLookups= "false " redirectPort= "8443 " acceptCount= "100 " debug= "0 " connectionTimeout= "20000 " disableUploadTimeout= "true " URIEncoding= "UTF-8 "/>