I have mvc spring app with logout controller, I want to remove some cookies when I send act param via get method. But cookies are still alive and no errors/warnings, I trying a lot of things, but no result. Maybe anybody faced with a same problems?
EDIT: I think It's not dublicate, because this code works fine without spring mvc. SetContentType text/html doesn't solve a problem.
@RequestMapping(value = {"/{act}", "/{act}/"}, method = RequestMethod.GET)
public void getLogout(@PathVariable(value = "act", required = true) String act,
ModelMap model,
HttpServletRequest request,
HttpServletResponse response,
HttpSession session) throws IOException,
ServletException {
if(act.equals("logout")) {
CacheControl.maxAge(0, TimeUnit.SECONDS);
Cookie login_auth;
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("login_auth")) {
login_auth = cookie;
login_auth.setMaxAge(0);
response.addCookie(login_auth);
response.sendRedirect(String.format("%s%s", request.getContextPath(), "/login"));
}
}
}
}
}
So, after a lot of tests I see that for /admin/logout was set another cookie with a same name and correct MaxAge = 0, It's not expectable behaviour.
I solved It when change /admin/logout mapping on simple /admin?act=logout