日期:2014-05-17 浏览次数:21154 次
<filter>
<filter-name>CharFilter</filter-name>
<filter-class>com.test.CharFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
public class CharFilter implements Filter
{
private String charFilter;
@Override
public void destroy()
{
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest)arg0;
arg0.setCharacterEncoding(charFilter);
arg2.doFilter(request, arg1);
}
@Override
public void init(FilterConfig arg0)
throws ServletException
{
charFilter = arg0.getInitParameter("encoding");
}
}