spingboot:登出功能
登錄功能可以銷毀session或者刪除session的屬性來實現
session.invalidate(); session.removeAttribute("ID");這里的ID是我登陸時存入的session
我本來的想法是這樣的,先把session消滅,然后return到主頁,通過登陸攔截器把他踢回登陸頁面。
錯誤示范
@RequestMapping("/logout")public String logout(HttpSession session){session.invalidate();return "index";}結果
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Cannot create a session after the response has been committed
是因為我這里invalidate()直接把session設置為失效。但是session失效的同時 瀏覽器會立即創建一個新的session。這也就是為什么他提示我們Cannot create a session after the response has been committed我們的代碼上并沒有創建session。是服務器幫我們重新創建了一個session。
然后我改成
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed
也就是不能再請求提交之后再轉發了。
于是我改成
就可以了
總結
以上是生活随笔為你收集整理的spingboot:登出功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二年级上册计算题_二年级上册数学计算题复
- 下一篇: linux中的or和and的区别,扣丁学