ActionContext.getContext().getSession() 的意义

1:

Java代码   Java代码
Java代码
  1. ActionContext.getContext().getSession()
Java代码 ActionContext.getContext().getSession()

这个方法获得的不是HttpSession对象,而是一个Map对象。

要存值进去或者取值需要用以下方法

2:用法

Java代码   Java代码
Java代码
  1. ActionContext.getContext().getSession().put("validateCode", s);
  2. ActionContext.getContext().getSession().get("validateCode")
Java代码 ActionContext.getContext().getSession().put("validateCode", s); ActionContext.getContext().getSession().get("validateCode")

以上方法和session.setAttribute();session.getAttribute();的作用相同,并且可以混用


经验分享 程序员 微信小程序 职场和发展