public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (debug) log("AuthenticationFilter:doFilter()");
RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest)request);
ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse)response);
doBeforeProcessing(wrappedRequest, wrappedResponse);
System.out.println("in filter!!!!!!!!!!!!!!!!!!");
if(wrappedRequest.getSession().getAttribute("user")==null)
{
System.out.println("you do not have permission jump!!!!!!!!!!!!!!!!!!!!!!!");
wrappedResponse.sendRedirect(wrappedRequest.getContextPath()+"/home/login.jsp");
}
Throwable problem = null;
try {
chain.doFilter(request, response);
}
catch(Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that.
problem = t;
t.printStackTrace();
}
doAfterProcessing(wrappedRequest, wrappedResponse);
// If there was a problem, we want to rethrow it if it is
// a known type, otherwise log it.
if (problem != null) {
if (problem instanceof ServletException) throw (ServletException)problem;
if (problem instanceof IOException) throw (IOException)problem;
sendProcessingError(problem, response);
}
}
加粗字体为检查登陆逻辑,如果符合条件,触发重定向,则会报错:
java.lang.IllegalStateException: PWC1227: Cannot forward after response has been committed
修改方法:在if块最后加入return语句。