大约ActionContext.getContext()使用体验

    这是我在另一个人的博客看了,原来博客的时间长一点,我把它简化了一下,运营商,以方便它看起来。

 

    为了避免与Servlet API耦合在一起,方便Action类做单元測试,Struts 2对HttpServletRequest、HttpSession和ServletContext进行了封装,构造了三个Map对象来替代这三种对象,在Action中。直接使用HttpServletRequest、HttpSession和ServletContext相应的Map对象来保存和读取数据。

(一)通过ActionContext来获取request、session和application对象的LoginAction1

  

在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

posted on 2015-06-17 14:21  gcczhongduan  阅读(134)  评论(0编辑  收藏  举报