This article describes the JSP page transfer value garbled filtering method. Share to everyone for your reference, specific as follows:
1. Filter class:
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 File configuration:
<?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 configuration--> <filter > <filter-name>CharacterEncodingFilter</filter-name> <!--this name with <filter-mapping> under < Filter-name> the same--> <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-lis t> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
When I submit with the default submission of <form>, this method can not filter, need to set method= "POST" to filter
I hope this article will help you with JSP program design.