在action中获取到request/response/session/application对象:
一、
二、
不能获得response 对象
注:
Static ActionContext getContext() ---获得当前线程的向下文
Object get(Object key) ---- getAttribute()
void put( Object key, Object value ) ---- setAttribute()
Map getParameter() 相当于Servlet中的getParameterMap()
Map getApplication() 对应于ServletContext
·ActionContext
ActionContext(com.opensymphony.xwork.ActionContext)是Action执行时的上下文,上下文可以看作是一个容器(就是一个Map而已),它存放的是Action在执行时需要用到的对象,比如:在使用WebWork时,我们的上下文放有请求的参数(Parameter)、会话(Session)、Servlet上下文(ServletContext)、本地化(Locale)信息等。WebWork负责将Servlet相关数据转换为与ServletAPI无关的Map对象(即ActionContext),使得xwork的Action实现与web层、逻辑层与表现层的解耦。
在每次执行Action之前都会创建新的ActionContext,ActionContext是线程安全的,也就是说在同一个线程里ActionContext里的属性是唯一的,这样我的Action就可以在多线程中使用。我们可以通过ActionContext的静态方法:ActionContext.getContext()来取得当前的ActionContext对象。
·ServletActionContext
提供直接与Servlet容器交互的途径。通过它,可以取得HttpServletRequest、HttpServletResponse 、ServletConfig、ServletContext、PageContext对象。但是,使用ServletActionContext意味着Action与ServletAPI的紧密耦合。
一、
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session = request.getSession();
ServletContext application = ServletActionContext.getServletContext();
二、
ActionContext context = ActionContext.getContext();
Map request = (Map)ActionContext.getContext().get("request");
Map session = ActionContext.getContext().getSession();
Map application = context.getApplication();
不能获得response 对象
注:
Static ActionContext getContext() ---获得当前线程的向下文
Object get(Object key) ---- getAttribute()
void put( Object key, Object value ) ---- setAttribute()
Map getParameter() 相当于Servlet中的getParameterMap()
Map getApplication() 对应于ServletContext
·ActionContext
ActionContext(com.opensymphony.xwork.ActionContext)是Action执行时的上下文,上下文可以看作是一个容器(就是一个Map而已),它存放的是Action在执行时需要用到的对象,比如:在使用WebWork时,我们的上下文放有请求的参数(Parameter)、会话(Session)、Servlet上下文(ServletContext)、本地化(Locale)信息等。WebWork负责将Servlet相关数据转换为与ServletAPI无关的Map对象(即ActionContext),使得xwork的Action实现与web层、逻辑层与表现层的解耦。
在每次执行Action之前都会创建新的ActionContext,ActionContext是线程安全的,也就是说在同一个线程里ActionContext里的属性是唯一的,这样我的Action就可以在多线程中使用。我们可以通过ActionContext的静态方法:ActionContext.getContext()来取得当前的ActionContext对象。
·ServletActionContext
提供直接与Servlet容器交互的途径。通过它,可以取得HttpServletRequest、HttpServletResponse 、ServletConfig、ServletContext、PageContext对象。但是,使用ServletActionContext意味着Action与ServletAPI的紧密耦合。