struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wesley Wannemacher" <W...@doubleatrailer.com>
Subject RE: Struts2 set data to session
Date Mon, 30 Oct 2006 15:07:51 GMT
In struts2, you have to have your action implement the 'SessionAware'
interface. This interface means implementing one method (void
setSession( java.util.Map session)). This will/should give you access to
the true session object. 

There is also 'RequestAware,' but you should note that unit testing of
your actions will become more difficult since your objects will be tied
to a servlet environment.

-Wes 

> -----Original Message-----
> From: frankiestd168 [mailto:chanhangfai@hotmail.com] 
> Sent: Monday, October 30, 2006 9:56 AM
> To: user@struts.apache.org
> Subject: Struts2 set data to session
> 
> 
> Before in Struts1, I can set data to session/request in 
> action class, then
> display it in jsp..
> 
> In action class:  
> request.setAttribute("aName", "aValue");  
> request.getSession().setAttribute("bName, ""bValue");
> 
> then display value in jsp:  
> <%= (String)request.getAttribute("aName")  %>
> <%= (String)session.getAttribute("bName") %>
> 
> 
> But in Struts2, how can I do that?
> e.g. I used Mailreader sample code, I tried in action class, execute()
> function, do this...
>         Map mySession = this.getSession();
>         mm.put("cName", "cValue");
>         this.setSession(mm);
> 
> but in jsp, <%= session.getAttribute("cName") %> is null.
> 
> Any idea?
> -- 
> View this message in context: 
> http://www.nabble.com/Struts2-set-data-to-session-tf2539904.ht
> ml#a7076046
> 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
> 
> 

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


Mime
View raw message