zoukankan      html  css  js  c++  java
  • 关于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

  • 相关阅读:
    noi.ac NOI挑战营模拟赛1-5
    TJOI2015 弦论
    CQOI2018 破解D-H协议
    NOI2013 矩阵游戏
    NOI2015 荷马史诗
    NOI2015 寿司晚宴
    SDOI2014 重建
    NOI1999 生日蛋糕
    NOI2015 程序自动分析
    ZJOI2008 泡泡堂
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4015951.html
Copyright © 2011-2022 走看看