如果在某個url需要獲得session,並且要在session中暫存變量一般的方式就是這樣的
HttpSession session = request.getSession(true);
session.setAttribute(ExamViewParams.VIEW_EXAM_KEY, examViewParams);
如果這時候跳轉頁在, 如果採用的方式不正確,jsessionid就會顯示在url中,並不安全,辦法如下:
response 的方式
如果是項目內的跳轉,需要加上request.getContextPath() ,這時候瀏覽器地址裏面不會有jsessionid
String location = request.getContextPath() +"url";
response.sendRedirect(location);
spring mvc 的方式
如果用spring 的mvc的方式,url中就會有jsessionid
String location = "/controller/demo";
return "redirect:"+location;