spring退出登录如何清除登录信息
时间: 2023-05-12 07:07:41 浏览: 58
在 Spring 中,退出登录可以通过以下步骤清除登录信息:
1. 在 Spring Security 配置文件中配置 LogoutFilter,例如:
```
<http>
...
<logout logout-url="/logout" />
...
</http>
```
2. 在控制器中处理 /logout 请求,例如:
```
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
new SecurityContextLogoutHandler().logout(request, response, auth);
}
return "redirect:/login?logout";
}
```
这样就可以清除登录信息并重定向到登录页面。