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 {
}
}
?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>