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:登出功能的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 二年级上册计算题_二年级上册数学计算题复
- 下一篇: 云计算的一些常见安全风险