action
HttpServletRequest、HttpSession和ServletContext
Struts2对这个三个对象用Map进行了封装,我们就可以使用Map对象来存取数据了。
ActionContext actionContext = ActionContext.getContext(); //get HttpServletRequest Map<String,Object> request = (Map) actionContext.get("request"); request.put("a", "a is in request"); //get HttpSession //Map<String,Object> session = (Map) actionContext.get("session"); Map<String,Object> session = actionContext.getSession(); session.put("b", "b is in session"); //get ServletContext //Map<String,Object> application = (Map) actionContext.get("application"); Map<String,Object> application = actionContext.getApplication(); application.put("c", "c is in application");
jsp界面
${a} ${b} ${c} 或则request.getAttribute("a"); session.getAttribute("b); application.getAttribute("c");