springmvc session request

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

//获取request对象

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder

.getRequestAttributes()).getRequest();

//获取session对象

HttpSession session = request.getSession(true);



应用在一些变量需要做全局变量的时候。

如:购物车的数量

int shopcartnum = ...............;

session.setAttribute("shopcartnum", shopcartnum);


在jsp中获取全局变量

<div>${shopcartnum}</div>




springmvc session request

上一篇:向linux终端发消息


下一篇:jquery mobile 的事件测试