分享

java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

 CevenCheng 2012-05-11
在权限管理模块,对后台用户做粗粒度的登陆验证时,过滤器中抛出了如下的异常:
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

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

HttpServletRequest req = (HttpServletRequest) request;

HttpServletResponse res = (HttpServletResponse) response;

Employee emp = WebUtil.getEmployee(req);

//未登录, 或者 session 已经过期

if (!req.getRequestURI().equalsIgnoreCase(req.getContextPath() + this.ignoreURI) && 

!req.getRequestURI().equalsIgnoreCase(req.getContextPath() + "/control/logout")) { //避免登陆页面也被拦截

if (null == emp) { 

res.sendRedirect(ActionContext.getActionContext().getRequest().getContextPath() + "/control/login"); //重定向到登陆页面

return;

}

}

chain.doFilter(request, response);

}

注意看红色的 return; 这里是因为 response.sendRedirect(..) 之后 继续 chain.doFilter(..) 导致

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多