@RequestMapping("/logout")
public String logout(HttpSession session, HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
session.removeAttribute("user");//清除session
//request.getRequestDispatcher("login.html").forward(request, response);
// response.sendRedirect("login.html");
return "redirect:/login.html";
}
这里是直接重定向跳转。
@RequestMapping("/logout")
@ResponseBody
public String logout(HttpSession session, HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
session.removeAttribute("user");//清除session
//request.getRequestDispatcher("login.html").forward(request, response);
// response.sendRedirect("login.html");
return "redirect:/login.html";
}
如果加了@ResponseBody这个注解,返回的就是字符串或是json对象,跳转不了
要注意的是控制成如果使用了@RestController 那么就是@ResponseBody和@Controller合在了一块。如果真的确定不需要用到转发,重定向之类的,那么就可以使用@RestController。否则还是不用偷懒