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

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

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

    Java,J2EE,Weblogic,Oracle

    java項目隨筆
    隨筆 - 90, 文章 - 6, 評論 - 61, 引用 - 0
    數據加載中……

    java過濾器的小技巧

    <%@ page language="java" pageEncoding="GB2312"%>  與
    <%@ page contentType="text/html; charset=GB2312" pageEncoding="GB2312" language="java" errorPage=""%>區別:


    1.過濾器servlet
    public class CharsetFilter
        implements Filter
    {

        protected String encoding;
        protected FilterConfig filterConfig;
        protected boolean ignore;

        public CharsetFilter()
        {
            encoding = null;
            filterConfig = null;
            ignore = true;
        }

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

        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException
        {
            if(ignore || request.getCharacterEncoding() == null)
            {
                String encoding = selectEncoding(request);
                if(encoding != null)
                    request.setCharacterEncoding(encoding);
            }
            chain.doFilter(request, response);
        }

        public void init(FilterConfig filterConfig)
            throws ServletException
        {
            this.filterConfig = filterConfig;
            encoding = filterConfig.getInitParameter("encoding");
            System.out.println("11111111111:"+encoding);
            String value = filterConfig.getInitParameter("ignore");
            if(value == null)
                ignore = true;
            else
            if(value.equalsIgnoreCase("true"))
                ignore = true;
            else
            if(value.equalsIgnoreCase("yes"))
                ignore = true;
            else
                ignore = false;
        }

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

    2.在 web.xml 配置
     <filter>
      <filter-name>CharsetFilter</filter-name>
      <filter-class>com.easyjf.web.CharsetFilter</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>CharsetFilter</filter-name>
      <servlet-name>action</servlet-name>
     </filter-mapping>

    小結:
    在使用<%@ page language="java" pageEncoding="GB2312"%> 顯示的是亂碼。
    在使用<%@ page contentType="text/html; charset=GB2312" language="java" pageEncoding="GB2312"%>卻是正常的。


    1.jsp :
            <%@ page contentType="text/html; charset=gb2312" language="java">
           <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    2.web.xml中配置 gb2312

    posted on 2006-11-29 10:08 龔椿深 閱讀(1143) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产精品亚洲精品日韩已方| 18国产精品白浆在线观看免费| 国产最新凸凹视频免费| 亚洲色偷偷偷综合网| 黄色片在线免费观看 | 午夜神器成在线人成在线人免费| 亚洲欧洲日产国码在线观看| 最近免费中文字幕大全免费| 久久亚洲sm情趣捆绑调教| 免费无码VA一区二区三区| 久久久久亚洲av无码专区喷水| 在线成人爽a毛片免费软件| 亚洲高清在线mv| 4399好看日本在线电影免费| 伊人久久亚洲综合影院首页| 国产精品免费视频播放器| 老司机午夜免费视频| 亚洲精品网站在线观看不卡无广告 | 鲁丝片一区二区三区免费| 国产亚洲精品a在线无码| 91青青国产在线观看免费| 亚洲综合久久1区2区3区| 97人伦色伦成人免费视频| 亚洲AV性色在线观看| 亚洲日韩在线观看| 久久久久久AV无码免费网站下载| 亚洲成a人片在线观看中文app| 人妻视频一区二区三区免费| 免费手机在线看片| 久久国产亚洲电影天堂| 99久久免费国产精品特黄| 国产精品亚洲专区一区| 国产亚洲综合网曝门系列| 男女超爽刺激视频免费播放 | 78成人精品电影在线播放日韩精品电影一区亚洲 | 亚洲免费人成视频观看| 蜜臀亚洲AV无码精品国产午夜.| 国产亚洲成人在线播放va| 18禁成人网站免费观看| 日韩一级片免费观看| 亚洲色欲或者高潮影院|