Execute commandButton-beanFunction in WEB-INF/page.xhtml coming from forward

[亡魂溺海] 提交于 2019-12-12 01:56:40

问题


I'm using Java EE for an enterprise application on Glassfish 4.1, I've the following components:

a Java Servlet:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    this.setUser(um.getLoggedUser());

    final String indexPath =  "/Index.xhtml";
    final String creatorPath =  "/WEB-INF/HiddenPages/EventPageCreator.xhtml";

    if(creator())
        request.getRequestDispatcher("/WEB-INF/HiddenPages/Creator.xhtml").forward(request, response);
    else
        response.sendRedirect("/Index.xhtml");
}

The creator page that is under WEB-INF,is the page in which arises the problem: It's related to a ManagedBean method.

<h:form><p:menubar>
    <p:menuitem action="#{bean.logout()}" value="Logout" ajax="false">
</p:menuitem></p:menubar></h:form>

The bean:

@ManagedBean
@RequestScoped
public class Bean(){
    public void logout(){
        System.out.println("logout");
    }
}

The problem is that the page Creator.xhtlm is rightly loaded with all the css and also the properties given by that bean. The problem is that once I click on the logout menuitem it doesn't call the related function and an 500 Internal Error occurs, java.lang.IllegalStateException: Cannot forward after response has been committed.

来源:https://stackoverflow.com/questions/28041538/execute-commandbutton-beanfunction-in-web-inf-page-xhtml-coming-from-forward

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!