之前用PHP做小组项目中用到了session value。在PHP中session value的处理很简单而直接。
现在用Spring MVC写项目发现网上的关于Spring mvc 的Session教程写的都不太清楚。所以参考stackoverflow:https://stackoverflow.com/questions/18791645/how-to-use-session-attributes-in-spring-mvc
1. HttpServletRequest request
设置:
@RequestMapping(method = RequestMethod.GET)
public String testMestod(HttpServletRequest request){
ShoppingCart cart = (ShoppingCart)request.getSession().setAttribute("cart",value);
return "testJsp";
}
使用:
ShoppingCart cart = (ShoppingCart)session.getAttribute("cart");