This discussion is archived
2 Replies Latest reply: Jun 16, 2009 10:31 PM by 807574 RSS

Accessing httpsession in portletsession,

807574 Newbie
Currently Being Moderated

I have a problem with accessing httpsession attribute in portletsession,

I am able to get the session set inside the portletsession as shown in the below code,

Servlet class code,
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( response.encodeURL("/ip/invPrc") );
dispatcher.forward( request, response );

portlet class code,(inside doview)
PortletSession session = request.getPortletSession(false);
request = (RenderRequest)session.getAttribute("Invoice_Search_ses",1);

but when I try to set a attribute in httpsession inside servlet,
note :the servlet call was made thro the activexobject(ajax) from jsp as shown below,

reqobj = new ActiveXObject("MSXML2.XMLHTTP.3.0");"POST", "<%=IPHelper.getContextPath(request)+"/"+IPConstants.SERVLET_URL_INVOICE_SEARCH%>", true);
          reqobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
reqobj.onreadystatechange = loadSearchHandler;

servlet code,
out.print("<" + IPConstants.SERVLET_RESULT_ROOT + ">");
out.print("</" + IPConstants.SERVLET_RESULT_ROOT + ">");

i am not able to access the above session attribute in the portletsession.

I doubt since it is a call thro ajax, the session attribute is not applied on to the application scope. is there any other way to set the httpsession explicitly in the application scope which i am missing?

please help me in resolving this �..
  • 1. Re: Accessing httpsession in portletsession,
    807574 Newbie
    Currently Being Moderated
    In order to share attributes across the HttpSession/PortletSession, you must specify PortletSession.APPLICATION_SCOPE. Application scope is the default in your servlet, but you must specify it in your portlet to get at the attributes stored.

    Also, see my technical article on using HttpSession/PortletSession and AJAX in portlets:

    The code is in the portlet repository:
  • 2. Re: Accessing httpsession in portletsession,
    807574 Newbie
    Currently Being Moderated
    Hi ,
    I am struck with the issue of getting attributes set in portlet session into HTTP session.
    I have to show a file download dialog box when a user clicks on a button on my jsp.
    I wrote the code in jsp by setting content type and header. but it was throwing IllegalStateException when I tried to get ServletOutputStream. So I resorted to do the download code in a servlet.
    The problem in servlet is that when I say
    HttpSession session = request.getSession();
    it gives me a new session not the existing one. so i am not able to get the attribute i have saved in portletsession.In portlet's processaction i have set attribue as
    portletSession.setAttribute("myAttribute", Info, PortletSession.APPLICATION_SCOPE);
    I am using glassfish server.
    Please help me.