ActionContext actionContext = ActionContext.getContext();
actionContext.put("request", "request放入的值");
actionContext.getApplication().put("application", "application放入的值");
actionContext.getSession().put("session", "session放入的值");
方法二: 也可直接得到原始request对象,代码如下;
HttpServletRequest request = ServletActionContext.getRequest();
ServletContext servletContext = ServletActionContext.getServletContext();
request.setAttribute("requestObject", "requet对象");
request.getSession().setAttribute("sessionObject", "session对象");
servletContext.setAttribute("applicationObject", "application对象");
使用情况:当仅仅放入值时用方法一,只有当需要获取request对象时,如:
ServletContext servletContext = ServletActionContext.getServletContext();
servletContext.getRealPath(arg0);
才使用方法二;