使用应用程序Tomcat时出现奇怪的错误

时间:2014-01-06 00:21:29

标签: java jsf tomcat

我启动了tomcat,当第一页加载时,错误显示:

Jan 05, 2014 9:15:01 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [Faces Servlet] in context with path [/odontonew] threw exception
java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:252)
    at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:799)

此Filer中出现错误

public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        // HttpServletRequest req = (HttpServletRequest) request;
        //
        if (((HttpServletRequest) request).getRequestURI().contains(
                "security/form_login.xhtml")) {
            chain.doFilter(request, response);
            return;
        }

        UsuarioMBImpl usuarioMB = (UsuarioMBImpl) ((HttpServletRequest) request)
                .getSession().getAttribute("usuarioMB");

        if (usuarioMB == null || !usuarioMB.isLoggedIn()) {
            String contextPath = ((HttpServletRequest) request)
                    .getContextPath();
            ((HttpServletResponse) response).sendRedirect(contextPath
                    + "/security/form_login.xhtml");
        }

        chain.doFilter(request, response);
    }

如果我评论所有内容,只让“chain.doFilter ..”一切正常。

1 个答案:

答案 0 :(得分:0)

尝试在调用return后添加sendRedirect()语句:

    if (usuarioMB == null || !usuarioMB.isLoggedIn()) {
        String contextPath = ((HttpServletRequest) request).getContextPath();
        ((HttpServletResponse) response).sendRedirect(contextPath
                + "/security/form_login.xhtml");
        return;
    }