jiazg的gravatar头像
jiazg 2013-04-05 12:24:42

j2ee工程中文乱码解决方案小结

1.  确认工程编码是UTF-8
    右击工程名,单击properties,单击Resource,把Text file encoding设置为UTF-8
2. 确认工作空间为UTF-8
    单击windows->General->Workspace,把Text file encoding设置为UTF-8
3. 将jsp请求设置为UTF-8
    在页头添加<%@page contentType="text/html; charset=UTF-8" %>
4. 将jsp响应设置为UTF-8
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5. 如果还有乱码则在struts.xml中设置中文字符集:
    <constant name="struts.i18n.encoding" value="utf-8"></constant>
6. 如果还有乱码,在web.xml中添加中文过滤器:
    <filter>
        <filter-name>CharacterEncoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
              <param-name>encoding</param-name>
              <param-value>UTF-8</param-value>
          </init-param>
          <init-param>
              <param-name>forceEncoding</param-name>
              <param-value>true</param-value>
          </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
7. 如果还有乱码,在Action中的response字符集设置为UTF-8:
    ServletActionContext.getResponse.setCharacterEncoding("utf-8");
8. 如果还有乱码,则将服务器跳转配置设置为UTF-8:
    resin服务器的设置如下,修改conf目录下的resin.conf:
    <web-app id='/' document-directory="E:\WorkSpace\StrutsDemo\WebRoot">
          <character-encoding>utf-8</character-encoding>  <!--指定字符集编码-->
        <work-dir>D:/tools/resin-3.0.22/work</work-dir>  <!--指定work工作目录-->
         <temp-dir>D:/tools/resin-3.0.22/temp</temp-dir>  <!--指定临时工作目录-->
    </web-app>
    tomcat服务器设置如下,修改conf目录下的server.xml:
    <Connector port="80" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>   


最代码官方编辑于2014-1-5 21:06:49


打赏

文件名:j2ee工程中文乱码解决方案小结.zip,文件大小:1K 下载
  • /
    • /j2ee工程中文乱码解决方案小结.txt
最代码最近下载分享源代码列表最近下载
123456mmz  LV2 2020年12月21日
杨莎莎  LV6 2017年10月24日
钱多多先生  LV16 2016年10月12日
邓集海  LV19 2015年8月6日
artshell  LV14 2014年1月16日
最代码官方  LV167 2013年4月5日
最代码最近浏览分享源代码列表最近浏览
donglixue  LV6 2022年6月8日
2469095052  LV8 2021年2月1日
123456mmz  LV2 2020年12月21日
aibo3074  LV11 2020年12月1日
765105637  LV9 2020年10月23日
www-chrome  LV6 2020年8月31日
weepdf  LV11 2020年7月14日
wq5201129  LV1 2020年5月2日
小舟呀  LV12 2020年4月7日
wei199  LV6 2019年12月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友