Struts2的Action中取得Session、Request、Application对象的方法最常用的方法是:
private Map<String,Object> session; private Map<String,Object> request; private Map<String,Object> application; session = ActionContext.getContext().getSession(); request = (Map) ActionContext.getContext().get("request"); application = ActionContext.getContext().getApplication(); session.put("name", stu.getName()); request.put("age", stu.getAge()); application.put("name", stu.getName());jsp页面取得session,request,application的方法
一、利用Struts2的标签
h2><s:property value="#session.name" /></h2> <h3><s:property value="#request.age" /></h3> <h4><s:property value="#application.name" /></h4>
二、利用Jsp中默认对象
<%=session.getAttribute("name") %> <%=request.getAttribute("age") %> <%=application.getAttribute("name") %>