我有一个@ApplicationScoped bean,我从我的数据库中存储了一些数据。它为所有用户提供相同的数据,这就是我决定将其放在@ApplicationScope bean中的原因。
以下方面:
注销后我收到以下错误(在提交响应后无法创建会话):
10:02:37,284 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/kundenportal].[Faces Servlet]] (http-localhost-127.0.0.1-8080-5) Servlet.service() for servlet Faces Servlet threw exception: 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 com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122) [jsf-impl-2.1.7-jbossorg-2.jar:]
这是注销方法:
public String logout() {
((HttpServletRequest) FacesContext.getCurrentInstance()
.getExternalContext().getRequest()).getSession(false)
.invalidate();
return "loginFAILED"; // navigate to login-page
}
尝试使用错误的凭据登录时出现同样的错误。实际上,如果凭据错误,我会调用logout方法(无效,再次导航到登录页面)。此外,应显示咆哮消息。如果我想尝试另一次登录,我必须刷新页面,因为如果我点击登录按钮没有任何反应。
这是我的 @ApplicationScoped bean :
@Named
@ApplicationScoped
public class NewsController extends BaseController implements Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext
protected EntityManager em;
private List<News> newsList;
@PostConstruct
public void init() {
getAvailableNews();
}
public void getAvailableNews() {
if (newsList == null) {
newsList = new LinkedList<News>();
Query q = em.createNativeQuery(
"SELECT * FROM news WHERE sysdate BETWEEN ab AND bis+1",
News.class);
@SuppressWarnings("unchecked")
List<News> result = q.getResultList();
for (News n : result)
newsList.add(n);
}
}
public List<News> getNewsList() {
return newsList;
}
public void setNewsList(List<News> newsList) {
this.newsList = newsList;
}
}