|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Sharing session between portlet and servletHey, 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 |
|
|
RE: Sharing session between portlet and servletsetAttribute takes 2 parameters 1stis String, 2nd is Object setAttribute(String,Object) http://www.bluesunrise.com/portlet-api/javax/portlet/PortletSession.html HTH Martin ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Wed, 22 Oct 2008 17:10:47 +0200 > From: Michael.Vogt@... > To: pluto-user@... > Subject: Sharing session between portlet and servlet > > 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 > You live life beyond your PC. So now Windows goes beyond your PC. See how |
|
|
|
|
|
Re: Sharing session between portlet and servlet
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:
|
|
|
RE: Sharing session between portlet and servletEric wrote:
> 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. Nor should there be, unless/until the Servlet Specification decides to take it up, and resolve the issues. > Michael wrote: > > I also tried to use the overloaded method of setAttribute [with] > > PortletSession.APPLICATION_SCOPE) [and] PortletSession.PORTLET_SCOPE) > > without success. Sorry, you have been bitten by the atrociously ill-chosen naming of the manifest constants. APPLICATION_SCOPDE means "don't encode my keys and show me all keys" and "PORTLET_SCOPE" means "encode my keys, and only show me keys encoded with my unique id." It has nothing to do with any real scope, being specific as it is to the Servlet Session scope. You can communicate between applications using Portlet Messaging. Event handling portlets in each webapp can place values into their respective servlet sessions using APPLICATION_SCOPE (unencoded keys), making them available to collocated servlets. --- Noel |
| Free embeddable forum powered by Nabble | Forum Help |