<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大漠駝鈴

    置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
    Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論QQ群:428622099
    隨筆 - 238, 文章 - 3, 評論 - 117, 引用 - 0
    數據加載中……

    struts2中如何獲取Session,HttpServletRequest,HttpServletResponse

    1,How do we get access to the session?

    You can obtain the session attributes by asking the ActionContext or implementing SessionAware. Implementing SessionAware is preferred.

    Ask the ActionContext

     

    Map attibutes = ActionContext.getContext().getSession();

     

    Implement SessionAware

    The session attributes are available on the ActionContext instance, which is made available via ThreadLocal. _Preferred_

    • Ensure that servlet-config Interceptor is included in the Action's stack.
      • The default stack already includes servlet-config.
    • Edit the Action so that it implements the SessionAware interface.
      • The SessionAware interface expects a setSession method. You may wish to include a companion getSession method.
    • At runtime, call getSession to obtain a Map representing the session attributes.
    • Any changes made to the session Map are reflected in the actual HttpSessionRequest. You may insert and remove session attributes as needed.
    • Map parameters = this.getSession();
    To unit test a SessionAware Action, create your own Map with the pertinent session attributes and call setSession as part of the test's setUp method.


    2,How can we access the HttpServletRequest

    You can obtain the request by asking the ActionContext or implementing ServletRequestAware. Implementing ServletRequestAware is preferred.

    Ask the ActionContext

    The request is available on the ActionContext instance, which is made available via ThreadLocal.
    HttpServletRequest request = ServletActionContext.getRequest();

    Implement ServletRequestAware

    Preferred

    • Ensure that servlet-config Interceptor is included in the Action's stack.
      • The default stack already includes servlet-config.
    • Edit the Action so that it implements the ServletRequestAware interface.
      • The ServletRequestAware interface expects a setServletRequest method. You may wish to include a companion getServletRequest method.
    • At runtime, call getServletRequest to obtain a reference to the request object.
    It is more difficult to test Actions with runtime dependencies on HttpServletRequest. Only implement ServletRequestAware as a last resort. If the use case cannot be solved by one of the other servet-config interfaces (ApplicationAware, SessionAware, ParameterAware), consider whether an custom Interceptor could be used instead of Action code. (Review how servlet-config works for examples of what can be done.)


    3,How can we access the HttpServletResponse

    You can obtain the request by asking the ActionContext or implementing ServletResponseAware. Implementing ServletResponseAware is preferred.

    Ask the ActionContext


    The response is available on the ActionContext instance, which is made available via ThreadLocal.
    HttpServletResponse response = ServletActionContext.getResponse();

    Implement ServletResponseAware


    Preferred

    • Ensure that servlet-config Interceptor is included in the Action's stack.
      • The default stack already includes servlet-config.
    • Edit the Action so that it implements the ServletResponseAware interface.
      • The ServletResponseAware interface expects a setServletResponse method. You may wish to include a companion getServletResponse method.
    • At runtime, call getServletResponse to obtain a reference to the response object.
    t is more difficult to test Actions with runtime dependencies on HttpServletReponse. Only implement ServletResponseAware as a last resort. A better approach to solving a use case involving the response may be with a custom Result Type.

    posted on 2009-03-29 16:40 草原上的駱駝 閱讀(3773) 評論(0)  編輯  收藏 所屬分類: JAVA框架

    主站蜘蛛池模板: 2022国内精品免费福利视频| 国产精品亚洲专一区二区三区| 91精品成人免费国产| 亚洲Av无码乱码在线播放| 韩国亚洲伊人久久综合影院| 国产午夜免费秋霞影院| 欧洲亚洲综合一区二区三区| 在线观看免费精品国产| 特级毛片aaaa级毛片免费| 亚洲精品A在线观看| 水蜜桃视频在线观看免费播放高清 | 特级无码毛片免费视频| 亚洲国产精品一区二区第一页免| 免费无码国产V片在线观看| 亚洲片国产一区一级在线观看| 皇色在线免费视频| 亚洲毛片在线观看| 中国在线观看免费国语版| 亚洲AV无码一区二区三区性色 | 在线免费观看一级毛片| 亚洲精品av无码喷奶水糖心| 免费A级毛片无码A| 精品在线免费观看| 亚洲人成在线精品| 免费一级毛片一级毛片aa| 伊人免费在线观看高清版| 亚洲高清美女一区二区三区| 成人免费视频小说| 岛国精品一区免费视频在线观看| 亚洲日本精品一区二区| 免费视频中文字幕| 久久www免费人成精品香蕉| 亚洲蜜芽在线精品一区| 国产a不卡片精品免费观看| 在线观看片免费人成视频无码| 亚洲av日韩av综合| 国产亚洲欧洲Aⅴ综合一区| 免费阿v网站在线观看g| av午夜福利一片免费看久久| 亚洲天堂电影在线观看| 亚洲视频人成在线播放|