在我的java ee應用程序中,我無法實現註銷功能。這是當我嘗試實現它會發生什麼: 我有頭有我的應用程序的CSS部分header.xhtml: header.xhtml:(用於註銷代碼)託管bean註銷不起作用
<div class="userid-link"><img src="images/app.png" alt=""/><p><a href="#{loginBean.logoutAction()}">Logout</a></p></div>
代碼註銷:loginBean。 java的
public String logoutAction()
{
HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
try{
HttpSession session=req.getSession();
session.invalidate();
// req.logout();
}
catch(Exception e)
{
}
return"equityVolume.xhtml";
}
錯誤:
SEVERE: Error Rendering View[/ClientTemplate/userWatch.xhtml]
javax.el.ELException: /ClientTemplate/userWatch.xhtml @44,62 value="#{watchBean.ut}": java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
...
INFO: Exception when handling error trying to reset the response.
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
at...
主頁加載正確的,但是當我嘗試登錄時,userWatch.xhtml沒有正確渲染,我也得到次e以上錯誤,CSS也不適用。
watchBean.java
public List<UserTrack> getUt() {
HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session=req.getSession();// debugged and found that the session is null, this methos executes after login i.e. on the userWatch.xhtml that is redirected after login from homePage
this.uname=(String)session.getAttribute("uname");
ut=getAllUserTrack(uname);
return ut;
}
當我刪除從header.xhtml的logOutAction方法調用,然後一切工作正常,除了我得到註銷viewExpired錯誤:
<div class="userid-link"><img src="images/app.png" alt=""/><p><a href="#/homePage">Logout</a></p></div>
我該怎麼解決它?
,能不能請您使用'request.getSession(假)'和後的結果測試嗎? – higuaro
嘗試它仍然我得到相同的錯誤:( – z22
檢查出以下鏈接,他們描述了應用程序拋出您的'IllegalStateException'可能的解決方案: (http://stackoverflow.com/questions/8426121/cannot -create-a-session-after-the-response-has-been-committed-why) (http://stackoverflow.com/questions/5540695/pwc3999-cannot-create-a-session-after-the-響應已被提交) (http://stackoverflow.com/questions/8072311/illegalstateexception-cannot-create-a-session-after-the-response-has-been-commi) – higuaro