日期:2014-05-18  浏览次数:20628 次

servlet filter运行报错
源程序:
public   class   loginFilter   implements   Filter   {
//private   FilterConfig   filterConfig;  
String   onErrorUrl;  

/**
  *   Destruction   of   the   servlet.   <br>
  */
public   void   destroy()   {
//   Put   your   code   here
}

/**
  *   Initialization   of   the   servlet.   <br>
  *
  *   @throws   ServletException   if   an   error   occure
  */
public   void   init(FilterConfig   config)   throws   ServletException   {
//   Put   your   code   here
  //filterConfig   =   config;
    onErrorUrl   =   config.getInitParameter( "onError ");
    if   (onErrorUrl   ==   null   ||   " ".equals(onErrorUrl))   {
      onErrorUrl   =   "onError ";
    }
}

public   void   doFilter(ServletRequest   request,   ServletResponse   response,
      FilterChain   next)   throws   IOException,   ServletException   {
  HttpServletRequest   httpRequest   =   (HttpServletRequest)   request;
  HttpServletResponse   httpResponse   =   (HttpServletResponse)   response;
  HttpSession   httpSession   =   httpRequest.getSession();
/**
    *   @author   justin   ray  
    *   @see   页面缓存设定
    *   <br> 确保浏览器不缓存页面数据
    */    

httpResponse.setHeader( "Cache-Control ", "no-cache ");  
httpResponse.setHeader( "Cache-Control ", "no-store ");
httpResponse.setDateHeader( "Expires ",   0);
httpResponse.setHeader( "Pragma ", "no-cache ");  

    /**
    *   @author   justin   ray  
    *   @see   过滤未登录用户无效请求
    *   <br> 未登录用户请求跳转到/Logon.do
    */  
if   (httpSession.getAttribute( "username ")   ==   null)   {
      ActionErrors   errors   =   new   ActionErrors();
      errors.add(ActionMessages.GLOBAL_MESSAGE,   new   ActionMessage( "没有登录 "));
      httpRequest.setAttribute(Globals.ERROR_KEY,   errors);
68:       httpRequest.getRequestDispatcher(onErrorUrl).forward(httpRequest,httpResponse);
    }
70:   next.doFilter(request,   response);
}
}
运行报错:
java.lang.IllegalStateException:   Cannot   forward   after   response   has   been   committed
loginFilter.doFilter(login