ActionContext.getContext()详解
来源:互联网 发布:java字符串转日期代码 编辑:程序博客网 时间:2024/06/05 23:08
为了避免与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")%>
0 0
- ActionContext.getContext()详解
- actioncontext.getcontext()详解
- ActionContext.getContext()
- ActionContext.getContext()用法
- ActionContext.getContext()的用法
- 关于ActionContext.getContext()
- ActionContext.getContext()的用法心得
- 关于ActionContext.getContext()的用法
- Struts2中的ActionContext.getContext().getParameters()
- ActionContext.getContext()的用法心得
- 关于ActionContext.getContext()的用法
- 【Struts2】Struts2 : ActionContext.getContext().getParameters()
- ActionContext.getContext().getSession() 的意义
- ActionContext.getContext()的基本用法
- 关于ActionContext.getContext().getSession()返回null
- 关于ActionContext.getContext()的用法心得
- 关于ActionContext.getContext()的用法心得
- ValueStack与ContentMap (ActionContext.getContext().getValueStack().set())
- freemarker 整理手册
- java获取客户端IP地址以及mac地址
- 澤雷隨 (易經大意 韓長庚)
- 雷地豫 (易經大意 韓長庚)
- LeetCode 000 前言
- ActionContext.getContext()详解
- LeetCode 049 Anagrams
- 推荐算法之协同过滤实战
- JAVASE 面向对象 多态 单类设计模式 内部类 匿名内部类
- python是最适合初学者的语言
- 地山謙 (易經大意 韓長庚)
- 第14天 Android Touch事件学习 1 点击事件
- 火天大有 (易經大意 韓長庚)
- 天火同人 (易經大意 韓長庚)