问题
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