白云岛资源网 Design By www.pvray.com

本文实例讲述了JSP页面传值乱码过滤方法。分享给大家供大家参考,具体如下:

1.过滤器类:

package com.token.t1;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
  public void destroy() {
  }
  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {
     request.setCharacterEncoding("gbk");
    chain.doFilter(request, response);
  }
  public void init(FilterConfig arg0) throws ServletException {
  }
}

2.xml文件配置:

<"1.0" encoding="UTF-8""2.5" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!--过滤器配置-->
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>   <!--此名字与<filter-mapping>下<filter-name>相同即可 -->
    <filter-class>com.token.t1.CharacterEncodingFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern> /* </url-pattern>
  </filter-mapping>
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

当我用<form>的默认提交方式提交时,此方法过滤不了,需要设置 method="post",才可以过滤

希望本文所述对大家JSP程序设计有所帮助。

白云岛资源网 Design By www.pvray.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
白云岛资源网 Design By www.pvray.com