本文实例讲述了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程序设计有所帮助。

标签:
JSP,页面传值,乱码过滤

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“JSP页面传值乱码过滤方法”

暂无“JSP页面传值乱码过滤方法”评论...