Re: Sharing session between portlet and servlet
Eric Dalquist <[email protected]> Sat, 25 Oct 2008 08:21:01 -0500
| Newsgroups | gmane.comp.jakarta.pluto.user |
|---|---|
| Organization | UW DoIT |
| Message-ID | <[email protected]> |
The key of your question is "in a other context"
Portlets and Servlets in the _*same webapp*_ can share session
attributes placed in the session by the portlet in the
APPLICATION_SCOPE. There is no provision in the portlet API for sharing
session attributes between webapps.
-Eric
Vogt, Michael wrote:
> Hey, I've a problem to share session data from a portlet with an servlet (in a other context).
>
> An example, in portlet1 i put (or try to put) an attribute into the httpsession:
>
> PortletSession ps = PortletActionContext.getRequest().getPortletSession(true);
> String poco = (String)ctx.getAttribute("poco");
> if (poco == null) {
> System.out.println("poco == null!");
> ps.setAttribute("poco", ""+1);
> } else {
> int newLoco = Integer.parseInt(loco);
> newLoco++;
> ps.setAttribute("poco", ""+newLoco);
> System.out.println("poco rules: "+newLoco);
> }
> I also tried to use the overloaded method of setAttribute (ps.setAttribute("poco", ""+1, PortletSession.APPLICATION_SCOPE) and ps.setAttribute("poco", ""+1, PortletSession.PORTLET_SCOPE)) without success.
>
> In a servlet, i try to read out my http session (HttpSession sess = request.getSession(true) ...) but I never find my variable poco in the http session. The only thing that worked was using the portletcontext:
>
> PortletContext ctx = PortletActionContext.getPortletContext();
> String poco ...
>
> But in this case, the scope of the session variable was just portlet-wide (portlet wide=all portlets, which are in the same .war file / defined in portlet.xml).
>
> Some more information about my env.:
>
> I'm using:
> - springframework 2.0.8
> - struts 2.0.11.2
> - pluto 1.1.6
> - hibernate 3.2.1.ga
>
> Tomcat v6.0.14
>
> Server.xml
> <Connector port="500" maxHttpHeaderSize="8192"
> maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
> enableLookups="false" redirectPort="14443" acceptCount="100"
> connectionTimeout="20000" disableUploadTimeout="true" emptySessionPath="true" />
>
> <Context path="/customer"
> docBase="c:/whatever/blah/"
> crossContext="true" />
>
>
> cheers
>
>
> Michael Vogt
> Solution Engineer
>
> United Security Providers AG
> Bahnhofstrasse 4
> Postfach
> CH-3073 Gümligen
>
>
smime.p7s
(application/x-pkcs7-signature, 3.3 KB) - not displayed