struts2 怎么获取 httpsession

2025-05-18 17:39:46
推荐回答(1个)
回答1:

  1、Map map = ActionContext.getContext().getSession();

  2、HttpSession session = ServletActionContext.getRequest().getSession();

  3、让Action实现SessionAware接口,并实现public void setSession(Map session) {} 方法,Struts2会在实例化Action后调用该方法,通过方法参数将Session对象注入进来。如果我们想获取Session,我们可以定义成员变量,接收注入进来的Session对象。