问题描述
有时候在Controller中要redirect跳转到某一个地址,例如:
@RequestMapping(value = "/somepath") public String somePath(HttpSession session) { User user = (User) session.getAttribute("user"); if (user != null) { return "someView"; } return "redirect:/login"; } // or @RequestMapping(value = "/somepath") public ModelAndView somePath(HttpSession session) { User user = (User) session.getAttribute("user"); if (user != null) { return new ModelAndView("someView"); } return new ModelAndView("redirect:/login"); }
实际跳转的时候,会在路径上带上一长串jsessionid,不是很好看,例如 http://localhost:8080/login;jsessionid=12345ABCDEXXXXX
去掉的方式
1.如果是使用tomcat/SpringMVC容器,修改web.xml,增加如下:
<session-config> <tracking-mode>COOKIE</tracking-mode> </session-config>
2.如果是springBoot,修改application.yml,增加如下:
server: servlet: session: tracking-modes: cookie
文章评论