<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 草原上的駱駝 閱讀(3772) 評論(0)  編輯  收藏 所屬分類: JAVA框架

    主站蜘蛛池模板: 亚洲视频一区二区在线观看| 亚洲人成网站在线播放vr| 亚洲国产亚洲片在线观看播放| 久久久精品午夜免费不卡| 成人午夜亚洲精品无码网站| 在线播放国产不卡免费视频| 亚洲国产婷婷综合在线精品| 精品国产亚洲AV麻豆| 亚洲国产精品人人做人人爽| 一级毛片无遮挡免费全部| 精品亚洲视频在线观看| 91精品成人免费国产| 亚洲国产成人久久综合碰碰动漫3d | 男男AV纯肉无码免费播放无码| 亚洲mv国产精品mv日本mv| 歪歪漫画在线观看官网免费阅读| 亚洲欧美自偷自拍另类视| 亚洲AV无码一区二区三区国产| 黄桃AV无码免费一区二区三区| 日本久久久久亚洲中字幕| 久久精品免费一区二区喷潮| 偷自拍亚洲视频在线观看99| 在线亚洲97se亚洲综合在线| 最近免费中文字幕大全免费| 亚洲av无码专区青青草原| 亚洲午夜成人精品电影在线观看| 久久精品乱子伦免费| 亚洲中文字幕久久精品蜜桃 | 黄a大片av永久免费| 一级人做人爰a全过程免费视频| 亚洲国产精品成人精品无码区| 成人免费视频77777| 无遮挡a级毛片免费看| 亚洲成人在线电影| 日本一道高清不卡免费| 成人无码精品1区2区3区免费看| 亚洲最大的视频网站| 亚洲乱码国产一区网址| 18成禁人视频免费网站| 黄色三级三级三级免费看| 亚洲狠狠综合久久|