关于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中读取
- <body><h3>${sessionScope.user.username},${requestScope.greeting}。<br>本站的访问量是:${applicationScope.counter}</h3>
- </body>
(二)直接使用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对HttpSe ...
- 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对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"> & ...
随机推荐
- H53D旋转-遁地龙卷风
(-1)写在前面 首先图片是我从互联网上下载的,向这位前辈致敬.我用的是chrome49,没有加不同浏览器的前缀,jquery3.0,图片资源放在了我的百度云盘上http://pan.baidu.co ...
- Effective Java 读书笔记之九 并发
一.访问共享的可变数据时要同步 1.synchronized关键字既然保证访问的可见性也能保证原子性.而volatile修饰符只能保证变量的线程可见性. 2.增量操作符等不是原子性,多线程操作时可能导 ...
- Unity3d用户手册用户指南 电影纹理(Movie Texture)
http://www.58player.com/blog-2327-952.html 电影纹理(Movie Texture) 注意:这只是专业/高级功能. 桌面 电影纹理是从视频文件创建的动画纹理 ...
- [转载]JavaEE学习篇之——JQuery技术详解
原文链接:http://blog.csdn.net/jiangwei0910410003/article/details/32102187 1.简介2.工具3.jQuery对象 1.DOM对象转化成j ...
- [转载]JavaEE学习篇之——JDBC详解
原文链接:http://blog.csdn.net/jiangwei0910410003/article/details/26164629 目录1.摘要2.JDBC的使用步骤 1.注册驱动 只做一次 ...
- word20161128
1. accordion 英[əˈkɔ:diən] 美[əˈkɔ:rdiən] n.手风琴; adj.可折叠的; [例句]Where some people learned to play the a ...
- VirtualBox centos 6.5 minimal 开启网络
默认情况下载的centos 6.5 minimal是不开启网卡功能的,按照下面的步骤开启网卡. vi /etc/sysconfig/network-script/ifcfg-eth0 将其中的 ONB ...
- How to tile small texture image onto page as its background
You don’t need to set a big size image as the background of pages if the image is texture or uniform ...
- Python自动化之线程进阶篇
拓展知识 什么是CPU-bound(计算密集型) 和I/O bound(I/O密集型) ? I/O bound 指的是系统的CPU效能相对硬盘/内存的效能要好很多,此时,系统运作,大部分的状况是 CP ...
- python list 的+、+=和extend操作
据说后者在list很大的时候性能稍好. 于是测试了一把: import time def time_cost(func): def _time_cost(*args,**kw): t1=time.ti ...