熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Java Struts1.2中文亂碼處理

2022-06-13   來源: Java開源技術 

  建立文件繼承filter接口如下

  package orgwkjzfxfileEncoding;

  import javaioIOException;

  import javaxservletFilter;

  import javaxservletFilterChain;

  import javaxservletFilterConfig;

  import javaxservletServletException;

  import javaxservletServletRequest;

  import javaxservletServletResponse;

  public class Encoding implements Filter {

  public void destroy() {

  }

  /**

  * 中文亂碼處理

  * */

  public void doFilter(ServletRequest arg ServletResponse arg

  FilterChain arg) throws IOException ServletException {

  argsetCharacterEncoding(GBK);

  argsetCharacterEncoding(GBK);

  argdoFilter(arg arg);

  }

  public void init(FilterConfig arg) throws ServletException {

  // TODO Autogenerated method stub

  }

  }

  然後在webxml裡面配置如下

  <filter>

  <filtername>Encoding</filtername>

  <filterclass>orgwkjzfxfileEncodingEncoding</filterclass>

  </filter>

  <filtermapping>

  <filtername>Encoding</filtername>

  <urlpattern>/*</urlpattern>

  </filtermapping>

  試試ok!了


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28742.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.