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

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

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

    Rising Sun

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks
    ?1 package?cn.com.jsp;
    ?2
    ?3 import?java.io.IOException;
    ?4 import?javax.servlet.Filter;
    ?5 import?javax.servlet.FilterChain;
    ?6 import?javax.servlet.FilterConfig;
    ?7 import?javax.servlet.ServletException;
    ?8 import?javax.servlet.ServletRequest;
    ?9 import?javax.servlet.ServletResponse;
    10 import?javax.servlet.UnavailableException;
    11
    12 public ? class ?SetCharacterEncodingFilter?implements?Filter? {
    13 ???? protected ?String?encoding? = ? null ;
    14 ???? protected ?FilterConfig?filterConfig? = ? null ;
    15 ???? protected ?boolean?ignore? = ? true ;
    16
    17 ???? public ? void ?destroy()? {
    18 ???????? this .encoding? = ? null ;
    19 ???????? this .filterConfig? = ? null ;
    20 ????}

    21
    22 ???? public ? void ?doFilter(ServletRequest?request,?ServletResponse?response,
    23 ?????????????????????????FilterChain?chain)?throws?IOException,
    24 ????????????ServletException? {
    25
    26 ???????? // ?Conditionally?select?and?set?the?character?encoding?to?be?used
    27 ???????? if ?(ignore? || ?(request.getCharacterEncoding()? == ? null ))? {
    28 ????????????String?encoding? = ?selectEncoding(request);
    29 ???????????? if ?(encoding? != ? null )? {
    30 ????????????????request.setCharacterEncoding(encoding);
    31 ????????????}

    32 ????????}

    33
    34 ???????? // ?Pass?control?on?to?the?next?filter
    35 ????????chain.doFilter(request,?response);
    36
    37 ????}

    38
    39 ???? public ? void ?init(FilterConfig?filterConfig)?throws?ServletException? {
    40
    41 ???????? this .filterConfig? = ?filterConfig;
    42 ???????? this .encoding? = ?filterConfig.getInitParameter( " encoding " );
    43 ????????String?value? = ?filterConfig.getInitParameter( " ignore " );
    44 ???????? if ?(value? == ? null )? {
    45 ???????????? this .ignore? = ? true ;
    46 ????????}
    ? else ? if ?(value.equalsIgnoreCase( " true " ))? {
    47 ???????????? this .ignore? = ? true ;
    48 ????????}
    ? else ? if ?(value.equalsIgnoreCase( " yes " ))? {
    49 ???????????? this .ignore? = ? true ;
    50 ????????}
    ? else ? {
    51 ???????????? this .ignore? = ? false ;
    52 ????????}

    53
    54 ????}

    55
    56 ???? protected ?String?selectEncoding(ServletRequest?request)? {
    57 ???????? return ?( this .encoding);
    58 ????}

    59
    60 }


    相應的web.xml文件里的配置如下:

    ?1<web-app>
    ?2??<display-name>wwwrootSPAN style="COLOR: #800000">display-name>
    ?3??<description>MySQL?Test?AppSPAN style="COLOR: #800000">description>
    ?4??<filter>
    ?5????<filter-name>setCharacterEncodingFilterSPAN style="COLOR: #800000">filter-name>
    ?6????<display-name>setCharacterEncodingFilterSPAN style="COLOR: #800000">display-name>
    ?7????<description>setCharacterEncodingFilterSPAN style="COLOR: #800000">description>
    ?8????<filter-class>cn.com.jsp.SetCharacterEncodingFilterSPAN style="COLOR: #800000">filter-class>
    ?9????<init-param>
    10??????<param-name>encodingSPAN style="COLOR: #800000">param-name>
    11??????<param-value>GBKSPAN style="COLOR: #800000">param-value>
    12????SPAN style="COLOR: #800000">init-param>
    13??SPAN style="COLOR: #800000">filter>
    14??<filter-mapping>
    15????<filter-name>setCharacterEncodingFilterSPAN style="COLOR: #800000">filter-name>
    16????<url-pattern>/*SPAN style="COLOR: #800000">url-pattern>
    17??SPAN style="COLOR: #800000">filter-mapping>
    18……
    19SPAN style="COLOR: #800000">web-app>

    上面的代碼我也沒更改什么,看了后,了解了其中的些許流程。放入blog,留以備學吧
    posted on 2006-07-27 15:11 brock 閱讀(374) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 中文字幕无线码中文字幕免费| 亚洲黄色在线播放| 高潮内射免费看片| 国产在线不卡免费播放| 国产亚洲中文日本不卡二区| 美女视频黄免费亚洲| 91亚洲自偷在线观看国产馆| 免费观看激色视频网站bd| 亚洲国产精品久久丫| 一本岛高清v不卡免费一三区| 亚洲国产成人精品无码区在线网站| 91香蕉国产线在线观看免费| 久久亚洲国产伦理| 2019中文字幕免费电影在线播放| 77777_亚洲午夜久久多人| 人与禽交免费网站视频| 亚洲国产激情在线一区| 在线免费观看中文字幕| 日本激情猛烈在线看免费观看 | 亚洲国产成人AV网站| 免费v片在线观看无遮挡| 一级毛片免费视频网站| 国产亚洲精品无码成人| 久久久久久精品成人免费图片| 麻豆狠色伊人亚洲综合网站| 国产成人免费ā片在线观看| 国产精品免费看久久久香蕉| 亚洲第一精品福利| 18禁超污无遮挡无码免费网站国产| 精品亚洲成A人在线观看青青| 亚洲综合精品网站| 亚洲免费精彩视频在线观看| 亚洲综合在线一区二区三区| 亚洲AV无码乱码精品国产| 黄网站色视频免费在线观看的a站最新| 久久久久亚洲AV无码专区体验| 国产在线国偷精品产拍免费| 日本黄页网址在线看免费不卡| 亚洲人成在线影院| 国产在线观看免费不卡| 久久久免费精品re6|