Struts2的request session
程序员文章站
2022-05-23 10:25:41
...
1. 直接到ActionContext里找出来,Ps: 要把这个快速的获得方式放到方法体内,否则报空指针。。 原因有待考究
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = ServletActionContext.getRequest().getSession();
2. 还有另一种,IoC 依赖注入
private Map<String,Object> request ;
private Map<String,Object> session ;
public void setSession(Map<String, Object> request) {
// TODO Auto-generated method stub
this.request = request;
}
public void setRequest(Map<String, Object> request) {
// TODO Auto-generated method stub
this.request = request;
}
下一篇: Spring工程创建