<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免费一区二区三区| 黄色a三级免费看| 一区二区三区福利视频免费观看| 亚洲国产精品成人AV无码久久综合影院| 亚洲av永久无码精品网址| 免费无码看av的网站| 亚洲a∨国产av综合av下载 | 午夜视频在线在免费| 亚洲成人激情小说| 亚洲欧好州第一的日产suv| 成年人免费视频观看| 国产精品亚洲一区二区无码| 四虎永久在线免费观看| 一级一看免费完整版毛片| 亚洲熟女少妇一区二区| 久久久精品免费视频| 亚洲情a成黄在线观看动漫尤物| 无码国产精品一区二区免费模式| 久久精品国产亚洲AV大全| 在线精品一卡乱码免费| 亚洲成在人线aⅴ免费毛片| 免费播放春色aⅴ视频| 99久久成人国产精品免费| 亚洲综合激情九月婷婷 | 亚洲熟妇无码八AV在线播放| 青青操免费在线视频| 777亚洲精品乱码久久久久久 | 国产一区在线观看免费| 中文字幕免费观看视频| 亚洲成a人片7777| 四虎永久成人免费| 日本在线免费播放| 国产成人精品日本亚洲11| 亚洲av中文无码| 1000部拍拍拍18勿入免费视频下载 | 色影音免费色资源| 人禽伦免费交视频播放| 亚洲黄色中文字幕| 伊人久久亚洲综合影院| 免费看又黄又无码的网站| 精品国产_亚洲人成在线|