You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by tom tom <j_...@yahoo.com> on 2007/03/15 06:41:24 UTC

How to session attributes Struts 2.0.6

Hi,

How can we set the session variables which we used to
do in stuts 1.x. and thereafter access in the jsps.

e.g.

session.setAttribute("NAME","USER11");

and in jsp

 <logic:equal name="NAME" value="USER11">
          This message is for user 1
 </logic:equal>


How can we access to the session, should it be as 
follows

In execute method


  RenderRequest req =
PortletActionContext.getRenderRequest();

        

        

PortletSession session=req.getPortletSession();

        session.setAttribute("NAME","USER1");


 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by Felipe Rodrigues <fe...@yahoo.com.br>.
You can use the interceptor ServletConfig to get HTTPServletRequest and
HTTPServletResponse.

But hte best way is to implements SessionAware interface in your action
class.
Take a look at this link.
http://struts.apache.org/2.x/docs/how-do-we-get-access-to-the-session.html

regards,

Felipe


Tracy12 wrote:
> 
> Hi,
> 
> How can we set the session variables which we used to
> do in stuts 1.x. and thereafter access in the jsps.
> 
> e.g.
> 
> session.setAttribute("NAME","USER11");
> 
> and in jsp
> 
>  <logic:equal name="NAME" value="USER11">
>           This message is for user 1
>  </logic:equal>
> 
> 
> How can we access to the session, should it be as 
> follows
> 
> In execute method
> 
> 
>   RenderRequest req =
> PortletActionContext.getRenderRequest();
> 
>         
> 
>         
> 
> PortletSession session=req.getPortletSession();
> 
>         session.setAttribute("NAME","USER1");
> 
> 
>  
> ____________________________________________________________________________________
> Bored stiff? Loosen up... 
> Download and play hundreds of games for free on Yahoo! Games.
> http://games.yahoo.com/games/front
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-session-attributes-Struts-2.0.6-tf3406479.html#a9520542
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by Nate Drake <nd...@gmail.com>.
Can't help you out with that problem, as I haven't played with the Portlet
stuff.  Sorry.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by tom tom <j_...@yahoo.com>.
Hi,

It was my mistake I was refering to the wrong Action
class in my struts.xml

Please find my observations with regard to the portlet
session handling

1) I implemented the SessionAware interface and it's
method setSession and add the session attributes, This
works with no issues

2) in the Action class's execute method I did the
following

Map session = (Map)
ActionContext.getContext().get("session");
session.put("myId","This is myID");

This works fine


3) I tried the following in the execute method 

RenderRequest req =
PortletActionContext.getRenderRequest();
        
        
        PortletSession
session1=req.getPortletSession();
        session1.setAttribute("myId","my Test Id ew");


This works as well.



Summary is all above works and I could retrieve them
from the jsp which means it works as expected similar
to the normal struts 2.0.6 application.


Thanks





--- Nils-Helge Garli <ni...@gmail.com> wrote:

> Hi!
> 
> This is probably a missing feature in the portlet
> framework. The
> SessionAware interface aparently doesn't work when
> inside a portlet.
> The other approach you use should work, but if it
> doesn't, try using
> the ActionContext to get the session map and put it
> there.
> 
> Nils-H
> 
> On 3/16/07, tom tom <j_...@yahoo.com> wrote:
> > Hi,
> >
> > I implemented the following interface
> >
> > org.apache.struts2.interceptor.SessionAware;
> >
> > hence implemented the
> >
> > public void setSession(Map session) method and did
> add
> > the following attribute
> >
> > session.put("NAME","USER1");
> >
> > and in my jsp I have the following
> >
> > <s:property value="#session.NAME"/> <br>
> >
> > It works fine in a normal struts Web Application.
> >
> > But when I did the same in a Portlet Application,
> the
> > jsp does not print the value. Should I do any
> > additional steps, I was under the impression we
> can
> > write a portlet as similar to a web application.
> >
> > After that I tried the following
> >
> >  RenderRequest req =
> > PortletActionContext.getRenderRequest();
> >
> >  PortletSession session1=req.getPortletSession();
> >  session1.setAttribute("NAME","USER1");
> >
> >
> > but still jsp does not print the session values.
> >
> >
> > Can some one let me know how to proceed ont this.
> >
> >
> > thanks
> >
> >
> >
> >
> >
> >
> > --- Nate Drake <nd...@gmail.com> wrote:
> >
> > > Have your action implement SessionAware, and
> give it
> > > a setter of the form:
> > >
> > > public void setSession(Map session);
> > >
> > > You can then add things to this map, and they
> will
> > > be added into the session.
> > > Then you can access them in your JSP like this:
> > >
> > > <s:property value="#session\['NAME'\]"/>
> > >
> > >
> > > See these pages for more details:
> > >
> > >
> >
>
http://struts.apache.org/2.0.6/docs/how-do-we-get-access-to-the-session.html
> > >
> >
>
http://struts.apache.org/2.0.6/docs/application-session-request-objects-in-jsp.html
> > >
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail:
> > > user-help@struts.apache.org
> > >
> > >
> >
> >
> >
> >
> >
>
____________________________________________________________________________________
> > Expecting? Get great news right away with email
> Auto-Check.
> > Try the Yahoo! Mail Beta.
> >
>
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



 
____________________________________________________________________________________
Looking for earth-friendly autos? 
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by Nils-Helge Garli <ni...@gmail.com>.
Hi!

This is probably a missing feature in the portlet framework. The
SessionAware interface aparently doesn't work when inside a portlet.
The other approach you use should work, but if it doesn't, try using
the ActionContext to get the session map and put it there.

Nils-H

On 3/16/07, tom tom <j_...@yahoo.com> wrote:
> Hi,
>
> I implemented the following interface
>
> org.apache.struts2.interceptor.SessionAware;
>
> hence implemented the
>
> public void setSession(Map session) method and did add
> the following attribute
>
> session.put("NAME","USER1");
>
> and in my jsp I have the following
>
> <s:property value="#session.NAME"/> <br>
>
> It works fine in a normal struts Web Application.
>
> But when I did the same in a Portlet Application, the
> jsp does not print the value. Should I do any
> additional steps, I was under the impression we can
> write a portlet as similar to a web application.
>
> After that I tried the following
>
>  RenderRequest req =
> PortletActionContext.getRenderRequest();
>
>  PortletSession session1=req.getPortletSession();
>  session1.setAttribute("NAME","USER1");
>
>
> but still jsp does not print the session values.
>
>
> Can some one let me know how to proceed ont this.
>
>
> thanks
>
>
>
>
>
>
> --- Nate Drake <nd...@gmail.com> wrote:
>
> > Have your action implement SessionAware, and give it
> > a setter of the form:
> >
> > public void setSession(Map session);
> >
> > You can then add things to this map, and they will
> > be added into the session.
> > Then you can access them in your JSP like this:
> >
> > <s:property value="#session\['NAME'\]"/>
> >
> >
> > See these pages for more details:
> >
> >
> http://struts.apache.org/2.0.6/docs/how-do-we-get-access-to-the-session.html
> >
> http://struts.apache.org/2.0.6/docs/application-session-request-objects-in-jsp.html
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
> >
> >
>
>
>
>
> ____________________________________________________________________________________
> Expecting? Get great news right away with email Auto-Check.
> Try the Yahoo! Mail Beta.
> http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by tom tom <j_...@yahoo.com>.
Hi,

I implemented the following interface

org.apache.struts2.interceptor.SessionAware;

hence implemented the 

public void setSession(Map session) method and did add
the following attribute 

session.put("NAME","USER1");

and in my jsp I have the following

<s:property value="#session.NAME"/> <br>

It works fine in a normal struts Web Application.

But when I did the same in a Portlet Application, the
jsp does not print the value. Should I do any
additional steps, I was under the impression we can
write a portlet as similar to a web application.

After that I tried the following

 RenderRequest req =
PortletActionContext.getRenderRequest();
        
 PortletSession session1=req.getPortletSession();
 session1.setAttribute("NAME","USER1");


but still jsp does not print the session values.


Can some one let me know how to proceed ont this.


thanks






--- Nate Drake <nd...@gmail.com> wrote:

> Have your action implement SessionAware, and give it
> a setter of the form:
> 
> public void setSession(Map session);
> 
> You can then add things to this map, and they will
> be added into the session. 
> Then you can access them in your JSP like this:
> 
> <s:property value="#session\['NAME'\]"/>
> 
> 
> See these pages for more details:
> 
>
http://struts.apache.org/2.0.6/docs/how-do-we-get-access-to-the-session.html
>
http://struts.apache.org/2.0.6/docs/application-session-request-objects-in-jsp.html
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



 
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check. 
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to session attributes Struts 2.0.6

Posted by Nate Drake <nd...@gmail.com>.
Have your action implement SessionAware, and give it a setter of the form:

public void setSession(Map session);

You can then add things to this map, and they will be added into the session. 
Then you can access them in your JSP like this:

<s:property value="#session\['NAME'\]"/>


See these pages for more details:

http://struts.apache.org/2.0.6/docs/how-do-we-get-access-to-the-session.html
http://struts.apache.org/2.0.6/docs/application-session-request-objects-in-jsp.html


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org