CSDN博客

img GumPGZ

中文问题解决办法

发表于2004/7/14 10:37:00  764人阅读

分类: Java

1.在web.xml上添加:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    注:是"web-app_2_3.dtd"而不是"web-app_2_2.dtd"

2.然后在<web-app>中添加:
   <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>gumpgz.filter.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>GB2312</param-value>
        </init-param>
        <init-param>
            <param-name>ignore</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <servlet-name>action</servlet-name>
    </filter-mapping>
     注:"SetCharacterEncodingFilter"可以在tomcat/webapps/examples/WEB-INF/classes/filters里面找到.
          encoding一定要写"GB2312",不能写"GBK"

3.在jsp页面加入:
    <%@ page contentType="text/html; charset=GB2312"%>

该方法经过测试,在struts等中测试通过

0 0

相关博文

我的热门文章

img
取 消
img