本文实例讲述了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文件配置:
<?xml version="1.0" encoding="utf-8"?>
<web-app version="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程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!