jsf响应已经提交

时间:2013-02-15 12:45:28

标签: jsf redirect httpresponse

我正在使用JSF并尝试重定向页面,如果用户已经选择了一种语言(我从cookie中知道)。

所以我设置了一个听众:

<f:event listener="#{languageSelectionController.checkSkipLanguageSelection}" type="preRenderView" />

检查cookie是否存在,如果是,则重定向到主页(没有建议的语言选择页面)

 if (languageBean.isValidCookieDetected()) {
        FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), "languageSelection.xhtml", "toHome");
    }

但我得到了一个例外

java.lang.IllegalStateException: Response already committed
at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1602)
at weblogic.servlet.internal.ServletResponseImpl.sendRedirect(ServletResponseImpl.java:833)
at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:576)
at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:182)

我已阅读帖子What exactly does "Response already committed" mean? How to handle exceptions then?并尝试提高缓冲区大小但不会改变任何内容。

UDPATE:

我已使用以下代码设置过滤器:

    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    Cookie[] cookies = httpServletRequest.getCookies();
    for (Cookie c : cookies) {
        if (c.getName().equals("lang")) {
            httpServletResponse.sendRedirect("home.xhtml");
        }
    }
    chain.doFilter(request, response);

但我仍然得到了响应已经提交的异常......

任何人都可以帮助我吗?

由于

Stephane

0 个答案:

没有答案