關於 session 跳轉與 jsessionid 的問題

如果在某個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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章