四种方式:
1. 通过ActionContext来访问request,session,application对象
2. 通过实现RequestAware、SessionAware、ApplicationAware接口来访问request,session,application对象
3. 通过ServletActionContext来访问request,session,application对象
4. 通过实现ServletRequestAware接口来访问request,session,application对象
<wbr></wbr>
第二种用的最多
<wbr></wbr>
public class UserAction2 extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{<wbr><wbr><br><wbr><wbr><wbr> private Map <String,Object> <strong>request</strong>;<wbr><wbr><br><wbr><wbr><wbr> private Map <String,Object> <strong>session</strong>;<wbr><wbr><br><wbr><wbr><wbr> private Map <String,Object> <strong>application</strong>;<wbr><wbr><br><wbr><wbr><wbr> public String execute()</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> {<wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> request.put("requestKey", "requestValue");<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> session.put("sessionKey", "sessionValue");<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> application.put("applicationKey", "applicationValue");<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> return "success";<wbr><br><wbr><wbr><wbr> }<wbr><wbr><br><wbr><wbr><wbr> public void setRequest(Map<String, Object> request)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> {<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> this.request = request;<wbr><br><wbr><wbr><wbr> }<wbr><wbr><br><wbr><wbr><wbr> public void setApplication(Map<String, Object> application)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> {<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> this.application = application;<wbr><br><wbr><wbr><wbr> }<wbr><wbr><br><wbr><wbr><wbr> public void setSession(Map<String, Object> session)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> {<wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr> this.session = session;<wbr><br><wbr><wbr><wbr> }<wbr><br> }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr></wbr>
前台jsp页面获取后台值的方式
<s:property value="#request.requestKey"/>|<%=request.getAttribute("requestKey")%>
<s:property value="#session.sessionKey"/>|<%=session.getAttribute("sessionKey")%>
<s:property value="#application.applicationKey"/>|<%=application.getAttribute("applicationKey")%>
<wbr></wbr>
<wbr></wbr>
关于以上四种的详细说明,见下面这篇文章
<wbr></wbr>