<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 3, 文章 - 152, 評論 - 17, 引用 - 0
    數據加載中……

    徹底解決Tomcat 5.0.19中文亂碼

    一、Include的頁面亂碼

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

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

      解決:這兒可以有很多解決辦法,但是對于我們的中文環境,從根本上的解決辦法是將Tomcat 5.0.19的核心缺省編碼從ISO-8859-1修改為GBK 。可以在下面地址下載修改過的jar文件,

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

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

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

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

    //=================初學者注意,請將此文件放在WEB-INF\classes\filters下,
    //注意先以SetCharacterEncodingFilter.java保存,然后編譯一下,推薦使用eclipse
    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);
    }

    }
    //==================這段代碼是我在網上摘錄的,因為不知到出處所以無法標明作者
    //然后將下面<filter>開始的代碼加入到web.xml中,它位于WEB-INF下。
    //我的QQ:22070699
    //配置web.xml

    <filter>
     <filter-name>Set Character Encoding</filter-name>
     <filter-class>filters.SetCharacterEncodingFilter</filter-class>
     <init-param>
      <param-name>encoding</param-name>
      <param-value>GBK</param-value>
     </init-param>
    </filter>

    <filter-mapping>
     <filter-name>Set Character Encoding</filter-name>
     <url-pattern>/*</url-pattern>
    </filter-mapping>

    posted on 2005-02-15 11:29 閱讀(125) 評論(0)  編輯  收藏 所屬分類: J2ee

    主站蜘蛛池模板: 亚洲五月综合网色九月色| 久久亚洲AV无码精品色午夜麻豆| 亚洲熟妇无码AV| 在线天堂免费观看.WWW| 综合偷自拍亚洲乱中文字幕| 国拍在线精品视频免费观看 | 99在线热播精品免费99热| 亚洲国产精品无码久久久久久曰 | 亚洲视频在线视频| 国产va在线观看免费| 亚洲国产女人aaa毛片在线| 人妻丰满熟妇无码区免费| 久久亚洲精品无码AV红樱桃| h片在线免费观看| 亚洲视频人成在线播放| 久久精品国产亚洲AV久| 成年性生交大片免费看| 久久久久亚洲精品无码网址色欲 | 亚洲AV无码专区亚洲AV桃| 亚洲第一页综合图片自拍| 在线免费观看h片| 78成人精品电影在线播放日韩精品电影一区亚洲 | 亚洲国产人成网站在线电影动漫 | 亚洲一区精品无码| 最近免费最新高清中文字幕韩国| 亚洲成a人片在线观看播放| 免费的一级片网站| 中文字幕免费在线视频| 激情内射亚洲一区二区三区| 岛国大片免费在线观看| 国产99久久久久久免费看| 无码久久精品国产亚洲Av影片| 免费观看激色视频网站(性色)| 色噜噜的亚洲男人的天堂| 亚洲日本乱码在线观看| 性做久久久久久免费观看| jizz中国免费| 亚洲欧洲另类春色校园网站| 亚洲乱码日产精品a级毛片久久| 免费福利在线视频| 亚洲AV成人一区二区三区观看 |