关于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"> & ...
随机推荐
- IUYYLIUIU
#include<cstdio> using namespace std; int main() { printf("IIIIU !"); ; } //http://c ...
- 转:CentOS设置时区
from: http://os.51cto.com/art/201004/192805.htm 建议直接使用: 1. session 临时修改查看: tzselect. 然后数字键入,回车 2. 永久 ...
- 用bower命令创建项目
1,先安装bower,npm install -g bower 2,cd到项目文件夹下,安装项目所需要的依赖包,比如 npm install jquery;npm install bootstrap, ...
- git 添加文件
git 添加文件三步骤 git add filename git commit -m 'remarks' git push origin master
- 获取一个字符串Hello world中world首次出现的位置
获取一个字符串Hello world中world首次出现的位置 var str=“Hello world!” document.write(str.indexOf("world") ...
- C语言 百炼成钢6
//题目16:输入两个正整数m和n,求其最大公约数和最小公倍数. #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include< ...
- 发发关于JavaScript的感慨,随手记几个js知识碎片
最近一段时间写了很多JavaScript和jquery代码,越来越感觉js基础不牢固,写一句查半天,有时间肯定要系统的学一下. 不说了,先记一下最近学到的点东西,省的以后没时间系统学js还要再来查. ...
- Java6 String.substring()方法的内存泄露
substring(start,end)在Java编程里面经常使用,没想到如果使用不当,会出现内存泄露. 要了解substring(),最好的方法便是查看源码(jdk6): /** * <blo ...
- 2016喜剧《死侍》韩版.HD720P中英双字
导演: 蒂姆·米勒编剧: 略特·里斯 / 保罗·沃尼克 / 费边·尼谢萨 / 罗伯·莱菲尔德主演: 瑞恩·雷诺兹 / 莫蕾娜·巴卡林 / 艾德·斯克林 / T·J·米勒 / 吉娜·卡拉诺 / 更多.. ...
- win7桌面移到其他盘
打开"计算机",点"用户"--"Administrator"点进去,或者,打开我的文档,然后右键点"桌面""属 ...