• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    徹底解決Tomcat 5.0.19中文亂碼

    發布: 2007-6-22 07:38 | 作者: bruce  | 來源: Java研究組織  | 查看: 21次 | 進入軟件測試論壇討論

    領測軟件測試網

       
      一、Include的頁面亂碼

      現象:include進來的頁面出現亂碼,其它頁面正常。

      原因:Tomcat在缺省情況下使用ISO-8859-1編碼,但是在include時有時Tomcat不能正確根據外層.jsp文件的編碼解析include進來的文件,造成include進來的文件中的中文亂碼。



      解決:這兒可以有很多解決辦法,但是對于我們的中文環境,從根本上的解決辦法是將Tomcat 5.0.19的核心缺省編碼從ISO-8859-1修改為GBK ?梢栽谙旅娴刂废螺d修改過的jar文件,

      jasper-compiler.jar,jasper-runtime.jar位于/common/lib下,其它位于/server/lib下,將新的.jar文件替代原.jar即可。
      
      二、提交的數據亂碼

      現象:通過表單提交的數據出現亂碼。

      原因:原因未明?赡苁荰omcat在接收到請求后,并沒有能夠根據request中的信息提前正確的編碼方式。

      解決:可以添加一個設置字符集的Filter。

    package filters;

    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.UnavailableException;

    public class SetCharacterEncodingFilter implements Filter {
     protected String encoding = null;
     protected FilterConfig filterConfig = null;
     protected boolean ignore = true;

     public void destroy() {
      this.encoding = null;
      this.filterConfig = null;
     }

    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain)
    throws IOException, ServletException {

     // Conditionally select and set the character encoding to be used
     if (ignore || (request.getCharacterEncoding() == null)) {
      String encoding = selectEncoding(request);
      if (encoding != null)
       request.setCharacterEncoding(encoding);
     }

     // Pass control on to the next filter
     chain.doFilter(request, response);

    }

    public void init(FilterConfig filterConfig) throws ServletException {

     this.filterConfig = filterConfig;
     this.encoding = filterConfig.getInitParameter("encoding");
     String value = filterConfig.getInitParameter("ignore");
     if (value == null)
      this.ignore = true;
     else if (value.equalsIgnoreCase("true"))
      this.ignore = true;
     else if (value.equalsIgnoreCase("yes"))
      this.ignore = true;
     else
      this.ignore = false;

    }

    protected String selectEncoding(ServletRequest request) {
     return (this.encoding);
    }

    }

      配置web.xml

    <filter>
    。糵ilter-name>Set Character Encoding</filter-name>
    。糵ilter-class>filters.SetCharacterEncodingFilter</filter-class>
    。糹nit-param>
     。紁aram-name>encoding</param-name>
     。紁aram-value>GBK</param-value>
    。/init-param>
    </filter>

    <filter-mapping>
    。糵ilter-name>Set Character Encoding</filter-name>
    。紆rl-pattern>/*</url-pattern>
    </filter-mapping>

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>