关于ActionContext.getContext()的用法
为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest、HttpSession和ServletContext进行了封装,构造了三个Map对象来替代这三种对象,在Action中,直接使用HttpServletRequest、HttpSession和ServletContext对应的Map对象来保存和读取数据。
(一)通过ActionContext来获取request、session和application对象的LoginAction1
- ActionContext context = ActionContext.getContext();
- Map request = (Map)context.get("request");
- Map session = context.getSession();
- Map application = context.getApplication();
- request.put("greeting", "欢迎您来到程序员之家");//在请求中放置欢迎信息。
- session.put("user", user);//在session中保存user对象
- application.put("counter", count);
在JSP中读取
(二)直接使用ActionContex类的put()方法
ActionContext.getContext().put("greeting", "欢迎您来到http://www. sunxin.org");
然后在结果页面中,从请求对象中取出greeting属性,如下:
${requestScope.greeting} 或者 <%=request.getAttribute("greeting")%>
以下是原博客的地址,以备查阅http://apps.hi.baidu.com/share/detail/9065250
关于ActionContext.getContext()的用法的更多相关文章
- 关于ActionContext.getContext()的用法心得
转: 为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest.HttpSession和ServletContext进行了封装, ...
- ActionContext.getContext()用法
为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest.HttpSession和ServletContext进行了封装,构造了 ...
- ActionContext.getContext().getSession()
ActionContext.getContext().getSession() 获取的是session,然后用put存入相应的值,只要在session有效状态下,这个值一直可用 ActionConte ...
- 【转载】关于ActionContext.getContext().getParameters()获值问题
ActionContext.getContext().getParameters():一个学员问题的解答 2012-11-12 15:12:05| 分类: 默认分类 | 标签:struts2 ...
- <s:if>标签与ActionContext.getContext().getSession()
今天在做<s:if>标签中的属性值从 ActionContext.getContext().getSession().put("WW_TRANS_I18N_LOCALE" ...
- 关于ActionContext.getContext()的使用方法心得
这个也是我在另外一位仁兄的博客中看到的,原博客的有点长,我把它精简了一下,算看起来比較方便吧. 为了避免与Servlet API耦合在一起,方便Action类做单元測试,Struts 2对HttpSe ...
- 大约ActionContext.getContext()使用体验
这是我在另一个人的博客看了,原来博客的时间长一点.我把它简化了一下,运营商,以方便它看起来. 为了避免与Servlet API耦合在一起,方便Action类做单元測试,Struts 2对HttpSer ...
- ServletActionContext.getRequest().getSession() 和 ActionContext.getContext().getSession()
ActionContext.getContext().getSession(); 这个方法获取的session是struts封装过的一个Map类型的session,只能调用put()方法缓存数据. S ...
- ValueStack与ContentMap (ActionContext.getContext().getValueStack().set())
在方法 <action name="zilei" class="dtreeAction" method="zilei"> & ...
随机推荐
- C# 编码约定(C# 编程指南)
C#注释约定 将注释放到另一行,而不要放在代码行的末尾. 以大写字母作为注释文本的开头. 以句点结束注释文本. 在注释分隔符 (//) 和注释文本之间插入一个空格,如以下示例所示. // The fo ...
- [ORACLE错误]ORA-00001: unique constraint (...) violated并不一定是数据冲突
遇到这种情况,重建完表和索引后,终于正常INSERT了. prompt Importing table COUPON_ACTIVITYset feedback offset define offin ...
- iOS学习资料
1. UI整理 http://www.cocoachina.com/ios/20151110/14067.html. 2. iOS学习路径 http://www.cocoachina.com/ios/ ...
- [Elixir009]像GenServer一样用behaviour来规范接口
1.Behaviour介绍 Erlang/Elixir的Behaviour类似于其它语言中的接口(interfaces),本质就是在指定behaviours的模块中强制要求导出一些指定的函数,否则编译 ...
- 设置Eclipse中的tab键为4个空格的完整方法
1.点击 window->preference-,依次选择 General->Editors->Text Editors,选中右侧的 insert space for tabs;如下 ...
- C++ c++初识
//c++初识 #include<iostream> //包含c++标准头文件 //<iostream>和<iostream.h>格式不一样,前者没有后缀,实际上, ...
- Unity架构有点乱
1,没有合理的将公共的东西归入到基类中,而是分散到子类中,有许多重复. 比如 enbled的变量本应该是所有component所共有的一个属性,应该写在component.然而却发现并非这样,enbl ...
- CAN开发中遇到的奇怪问题
问题背景: 之前在做USBCAN2开发过程中,遇到一个奇葩问题,当我们加上其中某一句代码时,我们的程序会走不下去,得不到数据,而且在调试的过程中,你也不能暂停,不然,你也得不到数据.后来参考网上一篇帖 ...
- chrome扩展
chrome拓展开发实战:页面脚本的拦截注入 时间 2015-07-24 11:15:00 博客园精华区 原文 http://www.cnblogs.com/horve/p/4672890.htm ...
- Java从0开始学——字符串
#,java中的字符串是不可变的: #,比较两个字符串是不是相等,不能用==,因为那只能确认他们是否指向了同一个字符串对象: #,空串和null是不同的: #,代码点和代码单元 #,代码点表示 ...