【发布时间】:2018-11-12 04:59:38
【问题描述】:
HTML
<div ng-model="currentUser" id="userContainer">{{currentUser.email}}
<div class="dropdown-content">
<a href="/logout">Logout</a>
</div>
</div>
控制器
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public void logout(HttpServletResponse response, HttpServletRequest request) throws Exception {
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
cookie.setValue("");
cookie.setMaxAge(0);
response.addCookie(cookie);
}
}
response.sendRedirect("/index.html");
}
我正在运行一个 Spring Boot 应用程序,并将注销控制器定义为 GET 方法。
单击 Logout Div 时,url 变为http://******.ngrok.io/logout
但它从未命中 Controller 方法,但是当我使用 http://******.ngrok.io/logout URL 重新加载浏览器时,控制器会被命中并让我退出应用程序。
【问题讨论】:
标签: java html spring spring-boot