获取session的几种方法

如果觉得写得可以 或者太差 就 评论一下或者赞一下呗,多谢支持!!


1.在action中获取session

HttpServletRequest request = ServletActionContext.getRequest();

String RealRandomCode = (String) request.getSession().getAttribute("rand");


2.在jsp页面获取session

session.setAttribute("rand",sRand);


3.在spring的controller获取session

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();

 String string = (String) request.getSession().getAttribute("randomCode");



//获取response 的方法

HttpServletResponse response = 

((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();

你可能感兴趣的:(java,jsp)