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

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

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

    Rising Sun

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      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 }


    相應(yīng)的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,留以備學(xué)吧
    posted on 2006-07-27 15:11 brock 閱讀(369) 評論(0)  編輯  收藏

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 蜜臀91精品国产免费观看| 日韩亚洲产在线观看| 成人永久福利免费观看| 99re免费视频| 国产精品永久免费| 羞羞视频免费观看| 亚洲人成www在线播放| 91亚洲va在线天线va天堂va国产| 亚洲精品网站在线观看不卡无广告 | 亚洲中文字幕无码中文| 99人中文字幕亚洲区| 亚洲精品少妇30p| 亚洲男人第一无码aⅴ网站| 国产精品久久香蕉免费播放| 一区二区无码免费视频网站| 最好看的中文字幕2019免费| 你懂的网址免费国产| 中文字幕永久免费| 一个人看的免费视频www在线高清动漫| 亚洲成av人在线观看网站 | 99久久99久久精品免费看蜜桃| 国产亚洲免费的视频看| 99免费在线视频| 91视频精品全国免费观看| 一级黄色免费网站| 永久免费无码日韩视频| 无码毛片一区二区三区视频免费播放 | 成人免费视频一区二区| 免费国产草莓视频在线观看黄| 亚洲AV无码片一区二区三区| 亚洲人成色在线观看| 亚洲日韩看片无码电影| 亚洲av中文无码乱人伦在线观看| 亚洲精品456人成在线| 国产亚洲精品成人AA片| 亚洲欧洲AV无码专区| 亚洲av永久无码| 又黄又大的激情视频在线观看免费视频社区在线 | 一级毛片aa高清免费观看| 亚洲国产免费综合| 中文字幕无线码免费人妻|