0) ActionContext:代表当前Action执行的上下文。Action实例所操作到的数据都可以往ActionContext中存放,可以从中取。
ActionContext的实例是绑定到当前线程(ThreadLocal)上,也不用考虑线程安全问题。。。
获取ActionContext的实例的方法: ActionContext context = ActionContext.getContext();
1) 使用ActionContext提供的三个Map用于代表request/session/application三个属性作用域:
a) actionContext.put("key", Object value); --> 相当于request.setAttribute("key", Object value);
b) actionContext.getSession().put("key", Object value); --> session.setAttribute("key", Object value);
c) actionContext.getApplication().put("key", Object value); --> servletContext.setAttribute("key", Object value);
2) 直接使用ServletAPI:struts2也提供了一个叫ServletActionContext的实例,用于获取Servlet中的Request,Response, Session, ServletContext实例
HttpServletRequest servletActionContext.getRequest();
ServletContext servletActionContext.getServletContext();
ActionContext的实例是绑定到当前线程(ThreadLocal)上,也不用考虑线程安全问题。。。
获取ActionContext的实例的方法: ActionContext context = ActionContext.getContext();
1) 使用ActionContext提供的三个Map用于代表request/session/application三个属性作用域:
a) actionContext.put("key", Object value); --> 相当于request.setAttribute("key", Object value);
b) actionContext.getSession().put("key", Object value); --> session.setAttribute("key", Object value);
c) actionContext.getApplication().put("key", Object value); --> servletContext.setAttribute("key", Object value);
2) 直接使用ServletAPI:struts2也提供了一个叫ServletActionContext的实例,用于获取Servlet中的Request,Response, Session, ServletContext实例
HttpServletRequest servletActionContext.getRequest();
ServletContext servletActionContext.getServletContext();