日期:2014-05-17 浏览次数:20761 次
package com.cisco.My.server.admin.filter; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; public class My404Filter implements Filter { public static Logger log=Logger.getLogger("My404Filter.class"); @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request=(HttpServletRequest) req; String urlStr=request.getRequestURI().toString(); log.info("urlStr="+urlStr); MyHttpServletResponseWrapper response = new MyHttpServletResponseWrapper( (HttpServletResponse) resp); chain.doFilter(request, response); int status=response.getStatus(); log.info("status="+status); if(status==404 ){ log.info("find 404"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println("<html><body><p></p></body></html>"); } } @Override public void init(FilterConfig arg0) throws ServletException { } }