标签:des style io java ar sp on c 代码
package com.test.filter;
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 EncodeFilter implements Filter {
private String encode;
public EncodeFilter() { }
public void destroy() { }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{ response.setCharacterEncoding(encode);
chain.doFilter(request, response); }
public void init(FilterConfig fConfig) throws ServletException {
encode = fConfig.getInitParameter("encode"); }
}
web.xml
<filter>
<display-name>EncodeFilter</display-name>
<filter-name>EncodeFilter</filter-name>
<filter-class>com.test.filter.EncodeFilter</filter-class>
<init-param>
<param-name>encode</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
标签:des style io java ar sp on c 代码
原文地址:http://www.cnblogs.com/liyong0125/p/3991239.html