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

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

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

    Sung in Blog

               一些技術(shù)文章 & 一些生活雜碎
    一、Include的頁(yè)面亂碼

      現(xiàn)象:include進(jìn)來(lái)的頁(yè)面出現(xiàn)亂碼,其它頁(yè)面正常。

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

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

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

      現(xiàn)象:通過(guò)表單提交的數(shù)據(jù)出現(xiàn)亂碼。

      原因:原因未明。可能是Tomcat在接收到請(qǐng)求后,并沒(méi)有能夠根據(jù)request中的信息提前正確的編碼方式。

      解決:可以添加一個(gè)設(shè)置字符集的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>
     <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>

      現(xiàn)象:include進(jìn)來(lái)的頁(yè)面出現(xiàn)亂碼,其它頁(yè)面正常。

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

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

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

      現(xiàn)象:通過(guò)表單提交的數(shù)據(jù)出現(xiàn)亂碼。

      原因:原因未明。可能是Tomcat在接收到請(qǐng)求后,并沒(méi)有能夠根據(jù)request中的信息提前正確的編碼方式。

      解決:可以添加一個(gè)設(shè)置字符集的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>
     <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-09-02 10:09 Sung 閱讀(429) 評(píng)論(0)  編輯  收藏 所屬分類: Tomcat
    主站蜘蛛池模板: 亚洲精品无码久久不卡| 亚洲国产成人精品青青草原| 亚洲妇熟XXXX妇色黄| 精品无码人妻一区二区免费蜜桃| 亚洲乱码国产一区网址| 亚洲国产精品无码久久九九大片| 台湾一级毛片永久免费| 老司机免费午夜精品视频| 亚洲精品线在线观看| 国产精成人品日日拍夜夜免费| 亚洲av无码成人黄网站在线观看| baoyu116.永久免费视频| 国产gv天堂亚洲国产gv刚刚碰| 特级做a爰片毛片免费看| 亚洲网红精品大秀在线观看| 免费大香伊蕉在人线国产| 日本免费大黄在线观看| 曰批免费视频播放免费| 亚洲精品麻豆av| 成人午夜性A级毛片免费| 美女在线视频观看影院免费天天看| 亚洲春色在线视频| 色欲A∨无码蜜臀AV免费播| 亚洲成年轻人电影网站www| 日本免费无遮挡吸乳视频电影| 四虎影视久久久免费观看| 亚洲国产一区在线观看| 国产亚洲精AA在线观看SEE | 亚洲一区在线视频| 久久亚洲2019中文字幕| 在线成人a毛片免费播放| 黄色网页免费观看| 亚洲色偷偷偷综合网| 亚洲国产精品xo在线观看| 久久精品国产精品亚洲艾| 国产亚洲精品a在线观看| 国产青草视频免费观看97| 男女超爽刺激视频免费播放| 日本免费在线中文字幕| 在线免费视频你懂的| 免费福利资源站在线视频|