四种方式:
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>
http://blog.csdn.net/developer_java/article/details/5882976
分享到:
相关推荐
一个Demo告诉你struts2如何创建 request response session application
struts2访问application、session以及request等web资源的示例代码
NULL 博文链接:https://aimilin6688.iteye.com/blog/1279546
本文讲述了serlvet API无耦合的方式
NULL 博文链接:https://fish198398.iteye.com/blog/785319
2.修改题目1,将提交的“用户名信息”保存到request中,“密码信息”保存到session中,而“用户是否已经注册的判定信息”保存在application中,并在显示页面中,分别从request、session和application中获取数据并...
RequestMap,SessionMap,ApplicationMap, AttributeMap. struts提供两种方式访问session,request ,response,ActionContext 使用。 获得作用域及参数响应对象及三种符号说明
主要实现了用户的登录系统..并且验证了struts中的跳转..还有跳转到另一个action中的类型..跳转另一个action后显示出书籍信息......并且从request域中,session域和application整个应用程序域中获取信息..
8.7.2 使用M印类型的request、session、application 8.8 疑难解惑 8.8.1 Struts Prepare And Execute Filter过滤器 8.8.2 struts.xml文件配置出错 8.9 精彩回顾 第9章 庖丁解牛 ——揭密Struts2高级技术 9.1 本章...
一:访问或添加request/session/application属性 代码如下:public String scope() throws Exception{ ActionContext ctx = ActionContext.getContext(); ctx.getApplication().put(“app”, “应用范围”);//往...
主要介绍Struts2中访问Web元素的方法,希望能给大家做一个参考。
ActionForm maintains the session state for the Web application. ActionForm is an abstract class that is sub-classed for each input form model. When I say input form model, I am saying ActionForm ...
2:继承:子类继承父类,子类可以拥有父类中已定义的方法,并且子类可以修改父类中的方法使其更适合特殊需求。 3:多台:不同对象对统一消息作出不同响应称之为多态 4:抽象:忽略与当前主题无关的那些方面,将...
监听器 servlet application /session /request 6/8 个 1、拦截器 定义拦截器的包 <package name="myPackage" extends="struts-default"> 定义拦截器的核心 定义拦截器类 ...
d) 在bb.jsp中使用session的getAttribute方法取出的对象和aa.jsp中的beanName所引用的对象无关。 10) 用JSP2.0表达式语法在JSP页面上正确显示10+20的结果的是()。 a) ${10+20} b) ${10+20}; c) $(10+20)...
Struts2中WebWork框架使用XWork基于HTTP参数名执行操作和调用,将每个HTTP参数名处理为OGNL(对象图形导航语言)语句,而OGNL将: user.address.city=Bishkek&user['favoriteDrink']=kumys 转换为: action....
round方法返回与参数最接近的长整数,参数加1/2后求其floor. 27、String s = new String("xyz");创建了几个String Object? 两个 28、设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序...
第16章 Struts常用标签库 16.1、Struts标签库简介 16.2、Bean标签 16.2.1、标签 16.2.2、标签 16.2.3、资源访问标签 16.2.4、标签 16.2.5、标签 16.2.6、标签 16.2.7、国际化与标签 16.3、Logic...
当客户机第一次调用一个Stateful Session Bean 时,容器必须立即在服务器中创建一个新的Bean实例,并关联到客户机上,以后此客户机调用Stateful Session Bean 的方法时容器会把调用分派到与此客户机相关联的Bean实例...