【原创】在struts2中如何获取request等JSP内置对象和向它们赋值
在struts2的action里面是不能直接使用request对象,session对象和application对象的,因为它不想struts1的action,里面的execute传递的参数里有上述对象,那么当我们需要通过request等对象加载对象的时候该如何做呢???
①在acton里面获取request等对象
request对象:HttpServletRequest request = ServletActionContext.getRequest();
response对象:HttpServletResponse response = ServletActionContext.getResponse();
session对象:HttpSession session = request.getSession();
application对象:ServletContext servletContext = ServletActionContext.getServletContext();
②在action里面向request等对象加载数据
ActionContext ac = ActionContext.getContext();
ac.getApplication().put.("applicationName",Object); //Application
ac.getSession().put.("sessionName",Object); //Session
ac.put("requestName",Object); //request