简体   繁体   English

JSF 2.2 java.lang.IllegalStateException:提交响应后无法创建会话

[英]JSF 2.2 java.lang.IllegalStateException: Cannot create a session after the response has been committed

I've developed web apps using JSF 2.0 and now I decided to write app using Myfaces 2.2 and Tomcat 7.0.35 . 我已经使用JSF 2.0开发了Web应用程序,现在我决定使用Myfaces 2.2和Tomcat 7.0.35编写应用程序。 But I get exceptions and can't understand the reason of this. 但是我有例外,无法理解其原因。 I khow that stacktrace very similar to Mojara bug but I use Myfaces. 我知道该堆栈跟踪与Mojara错误非常相似,但是我使用Myfaces。

java.lang.IllegalStateException: Cannot create a session after the response has been committed
    org.apache.catalina.connector.Request.doGetSession(Request.java:2881)
    org.apache.catalina.connector.Request.getSession(Request.java:2316)
    org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:898)
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.getSession(ServletExternalContextImpl.java:150)
    org.apache.myfaces.view.impl.DefaultViewScopeHandler.generateViewScopeId(DefaultViewScopeHandler.java:128)
    org.apache.myfaces.view.ViewScopeProxyMap.getWrapped(ViewScopeProxyMap.java:76)
    org.apache.myfaces.view.ViewScopeProxyMap.isEmpty(ViewScopeProxyMap.java:94)
    org.apache.myfaces.renderkit.ErrorPageWriter._writeVariables(ErrorPageWriter.java:787)
    org.apache.myfaces.renderkit.ErrorPageWriter._writeVariables(ErrorPageWriter.java:769)
    org.apache.myfaces.renderkit.ErrorPageWriter.debugHtml(ErrorPageWriter.java:356)
    org.apache.myfaces.renderkit.ErrorPageWriter.handle(ErrorPageWriter.java:470)
    org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImpl.handle(MyFacesExceptionHandlerWrapperImpl.java:301)
    javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:61)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:287)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:200)

It's my page 这是我的页面

<h:body>
    <h:inputText value="#{loginBean.userName}"/>
    <h:inputSecret value="#{loginBean.password}"/>
    <h:commandButton value="Login"/>    
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <h:outputScript name="lib/bootstrap.min.js" library="js" target="body"/>
</h:body>

@ManagedBean(name = "loginBean")
@RequestScoped
public class LoginBean implements Serializable{

    private String userName;
    private String password;

    @PostConstruct
    public void init(){
        userName = "";
        password = "";
    }

    public void validateCredentials(){

    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

What can be the reason of this problem? 这个问题可能是什么原因?

Try to add: 尝试添加:

<h:form rendered="#{loginBean.initOk}">
   <h:inputText value="#{loginBean.userName}"/>
   <h:inputSecret value="#{loginBean.password}"/>
   <h:commandButton value="Login"/>   
   ............


<h:from>

@ManagedBean(name = "loginBean")
@RequestScoped
public class LoginBean implements Serializable{

 private String userName;
 private String password;
 private boolean initOk;


@PostConstruct
public void init(){
    userName = "";
    password = "";
    initOk =true;
}

all getter setter...

I have the same problem with my ConversationScoped bean. 我的ConversationScoped bean存在相同的问题。 I´m working with jboss AS 7.1 and jsf 2. 我正在使用jboss AS 7.1和jsf 2。

The following is my stacktrace: 以下是我的堆栈跟踪:

15:38:01,911 Information [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8080-1) Exception when handling error trying to reset the response.: java.lang.IllegalStateException: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2636) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.Request.getSession(Request.java:2375) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:841) [jbossweb-7.0.13.Final.jar:]
    at    

then I add the next method: 然后我添加下一个方法:

@PostConstruct
public void postConstruct() {
    FacesContext.getCurrentInstance().getExternalContext().getSession(true);

}

and the issue is no more. 问题不复存在了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring java.lang.IllegalStateException:在提交响应后无法创建会话 - Spring java.lang.IllegalStateException: Cannot create a session after the response has been committed java.lang.IllegalStateException - 在提交响应后无法创建会话 - java.lang.IllegalStateException - Cannot create a session after the response has been committed java.lang.IllegalStateException:添加`return`后提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed after add `return` Spring boot:java.lang.IllegalStateException:响应提交后无法调用sendError() - Spring boot : java.lang.IllegalStateException: Cannot call sendError() after the response has been committed java.lang.IllegalStateException:在servletfilter中提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed in servletfilter java.lang.IllegalStateException:在提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed java.lang.IllegalStateException:PWC1227:提交响应后无法转发……为什么要发送? - java.lang.IllegalStateException: PWC1227: Cannot forward after response has been committed…why it was comming? java.lang.IllegalStateException:在404上提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed on 404 随机java.lang.IllegalStateException:提交响应后无法转发 - Random java.lang.IllegalStateException: Cannot forward after response has been committed Hibernate和Jackson(java.lang.IllegalStateException:提交响应后无法调用sendError()) - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM