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

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

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

    成長中的記憶
    這是我的成長,這是我的天地,學習JAVA,只因快樂。
    posts - 4,comments - 16,trackbacks - 0
    web.xml
    <filter>
    ????????
    <filter-name>Set?Character?Encoding</filter-name>
    ????????
    <filter-class>mypack.Charset</filter-class>
    ????????
    <init-param>
    ????????????
    <param-name>encoding</param-name>
    ????????????
    <param-value>UTF-8</param-value>
    ????????
    </init-param>
    ????????
    <init-param>
    ????????????
    <param-name>ignore</param-name>
    ????????????
    <param-value>true</param-value>
    ????????
    </init-param>
    ????
    </filter>
    ??
    <filter-mapping>
    ????
    <filter-name>Set?Character?Encoding</filter-name>
    ????
    <servlet-name>action</servlet-name>
    ??
    </filter-mapping>
    過濾的類
    package mypack;
    import?java.io.*;
    import?javax.servlet.*;

    public?class?Charset?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?{
    ????????
    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;
    ????????
    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);
    ????}

    }

    這2個加進工程里,就可以直接運行了。不用在設置什么。
    至于數據庫最好設置為UTF-8.
    從此以后遠離中文出現亂碼的煩惱。哈哈哈
    posted on 2006-03-01 11:16 aiyoyoyo 閱讀(4016) 評論(2)  編輯  收藏 所屬分類: Struts

    FeedBack:
    # re: Struts過濾器的使用,已解決中文問題
    2008-12-30 01:01 | billmao
    好,直接房項目里改一下web.xml里的路徑就可以用了  回復  更多評論
      
    # re: Struts過濾器的使用,已解決中文問題[未登錄]
    2009-12-11 10:06 | qin
    這不是struts過濾器  回復  更多評論
      

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


    網站導航:
     
    主站蜘蛛池模板: 久久青草精品38国产免费| 成人性生免费视频| 久久久国产精品无码免费专区| 一区二区三区福利视频免费观看| 亚洲熟妇av一区二区三区| 亚洲综合久久一本伊伊区| 久久精品成人免费观看97| 成人毛片18女人毛片免费| 亚洲日本中文字幕天天更新| 国产精品区免费视频| 色婷婷亚洲十月十月色天| 一级毛片免费在线播放| 精品免费国产一区二区三区| 亚洲精品中文字幕无乱码| 永久免费av无码网站yy| 在线a亚洲v天堂网2018| 中文文字幕文字幕亚洲色| 精品免费国产一区二区三区| 黄色一级毛片免费| 成年女人视频网站免费m| 亚洲av无码专区国产不乱码| 两性刺激生活片免费视频| 亚洲综合无码一区二区| 国产成人精品免费午夜app| 亚洲av无码成人黄网站在线观看| 一进一出60分钟免费视频| 国产AⅤ无码专区亚洲AV| 一本久久A久久免费精品不卡 | 日本免费人成网ww555在线| 亚洲国产精品久久久久| 国产在线观a免费观看| 亚洲欧洲日产国码一级毛片| 亚洲精品乱码久久久久久蜜桃图片| 在线看片v免费观看视频777| 亚洲人成影院在线| 成人免费视频小说| 中文永久免费观看网站| 97se亚洲综合在线| 在线观看av永久免费| 国产精品亚洲片在线va| 精品亚洲一区二区三区在线观看 |