如果在某个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;

本文介绍如何在使用HttpSession和SpringMVC时避免URL中出现JSessionID,提高应用安全性。通过response和SpringMVC的redirect方式,实现项目内跳转而不会暴露JSessionID。
3238

被折叠的 条评论
为什么被折叠?



