成長中的記憶
          這是我的成長,這是我的天地,學(xué)習(xí)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個(gè)加進(jìn)工程里,就可以直接運(yùn)行了。不用在設(shè)置什么。
          至于數(shù)據(jù)庫最好設(shè)置為UTF-8.
          從此以后遠(yuǎn)離中文出現(xiàn)亂碼的煩惱。哈哈哈
          posted on 2006-03-01 11:16 aiyoyoyo 閱讀(4017) 評(píng)論(2)  編輯  收藏 所屬分類: Struts

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 白玉县| 张家口市| 蛟河市| 汨罗市| 怀仁县| 鹤山市| 加查县| 遵义市| 志丹县| 辽宁省| 龙海市| 扬中市| 疏附县| 南充市| 石台县| 河津市| 娄底市| 清水河县| 张家口市| 巨野县| 班玛县| 松溪县| 黄平县| 佛教| 武陟县| 遵义市| 综艺| 辽宁省| 新郑市| 蕲春县| 泸定县| 庄浪县| 肥乡县| 鸡西市| 文登市| 肇源县| 达拉特旗| 鄯善县| 潞西市| 西华县| 灌南县|