2013年7月26日

[JAVA] 在Filter導入錯誤頁

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * @author i-memo
 */
public class ImemoFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
        //init
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
     
        if (如果ooxx) {

   

                HttpServletRequest hrequest = (HttpServletRequest) request;
                HttpServletResponse hresponse = (HttpServletResponse) response;

                hresponse.sendRedirect(hrequest.getContextPath() + "/error.jsp");

                return;

         
        }
          chain.doFilter(request, response);
    }



    public void destroy() {
    }
}


沒有留言:

張貼留言