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

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

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

    The NoteBook of EricKong

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks

    A common issue when we’re using Portlet is about sharing data between PortletSession and HttpSession. Frequently we find code like this:

    Portlet snippet

    PortletSession session = request.getPortletSession();
    session.setAttribute("attribute_name","attribute_value");

    JSP snippet – Using JSTL

    <p>${sessionScope.attribute_name}</p>

    Result: The JSP prints out an empty value.

    Why does it happen ?

    It happens because the PortletSession and HttpSession have different scopes. By default, PortletSession uses portlet scope, as well as HttpSession uses application scope. Hence, an object into portlet scope cannot be accessible into application scope.

    Using the PortletSession into JSP

    One way to print a PortletSession value into a JSP is use the PortletSession within the JSP. We can do that using the following:

    <%
    PortletSession session = renderRequest.getPortletSession();
    out.println(session.getAttribute("attribute_name");
    %>

    This doesn’t sound good. We intend to use JSTL instead scriptlet and the approach above doesn’t fit in our requirement. Because of this we’re going to use one of the below approaches.

    Converting PortletSession into HttpSession within a Portlet

    Within the portlet, we can use a code like this:

    HttpServletRequest httpRequest = WpsStrutsUtil.getHttpServletRequest(request);
    HttpSession session = httpRequest.getSession(true);
    session.setAttribute("attribute_name","attribute_value");

    The code above simply retrieve a HttpServletRequest and then we created a HttpSession.

    It definatelly works, but we can do even better. Check the next example out.

    Changing the PortletSession scope

    As describe above, by default the PortletSession scope is a Portlet scope. As you should know, JSTL reads Application Scope. Fortunately, there is a simple way to change the default PortletSession scope. Simply add one more parameter in the setAttribute method.

    PortletSession session = request.getPortletSession();
    session.setAttribute("attribute_name","attribute_value",PortletSession.APPLICATION_SCOPE);

    Awesome, huh? In this way, we can use JSTL to get the values from Session.

    Conclusion

    I’m not a Portet specialist, however I’ve already found many problem regarding the PortletSession and HttpSession. If you’re facing a problem like this, check your code out and try the approaches above.

    If you have any question or comment, fell free to leave your message below.

    posted on 2011-11-09 12:14 Eric_jiang 閱讀(200) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 精品在线视频免费| 麻豆安全免费网址入口| 中文字幕免费在线| 亚洲好看的理论片电影| 久久精品无码专区免费东京热| 亚洲av永久无码精品网站| 久久久久免费看成人影片| 久久亚洲AV成人无码国产 | 亚洲精品无码久久久久| 免费无码av片在线观看| 亚洲av永久无码精品漫画| 午夜影院免费观看| 亚洲乱码一二三四区麻豆| 成年私人影院免费视频网站| 亚洲精品无码久久久久久| 亚洲国产成人五月综合网| 免费毛片在线看不用播放器 | 成人亚洲国产精品久久| 亚洲国产中文字幕在线观看| 91精品成人免费国产| 亚洲精品无码不卡| 最近中文字幕免费mv视频7| 337P日本欧洲亚洲大胆艺术图| 国产亚洲成人在线播放va| 可以免费观看的毛片| 中文字幕亚洲男人的天堂网络| 国产三级免费电影| 中国黄色免费网站| 亚洲小视频在线播放| 免费一级毛片在线播放不收费| 两个人看的www免费高清| 激情五月亚洲色图| 久久久久久久亚洲精品| 足恋玩丝袜脚视频免费网站| 美女免费精品高清毛片在线视| 亚洲va久久久噜噜噜久久狠狠| 性感美女视频免费网站午夜 | 免费无码中文字幕A级毛片| 亚洲真人无码永久在线观看| 亚洲国产精品狼友中文久久久| 精品一区二区三区无码免费视频|