日期:2014-05-19  浏览次数:20891 次

JSP过滤器无效
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 Chin implements Filter{
private String ccode;
public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(ccode);
response.setCharacterEncoding(ccode); 

chain.doFilter(request, response);

}

public void init(FilterConfig filterConfig) throws ServletException {
ccode=filterConfig.getInitParameter("ccode");


}

}
 <filter>
  <filter-name>encode</filter-name> 
  <filter-class>com.SSH5.Chin</filter-class>
  <init-param>
  <param-name>ccode</param-name>
  <param-value>utf-8</param-value>
  </init-param> 
  </filter>
 <filter-mapping>
  <filter-name>encode</filter-name> 
  <url-pattern>/*</url-pattern> 
  </filter-mapping>
 

------解决方案--------------------
lz怎么知道无效了? 是没走过滤器吗? 如果走了过滤器还乱码 貌似不能说过滤器无效吧,可能还有其他原因导致乱码滴。。。
------解决方案--------------------
重新加载一次