You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ganesh <em...@yahoo.co.in> on 2011/04/07 11:47:51 UTC

Accessing session objects other than action in Struts 1.x

Hello all,

I am using Struts 1.0.2. 

I want to access session objects in a class other than Action. Is there any way to acheive it rather than passing the information via parameter to each and every function?

Regards
Ganesh

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


RE: Accessing session objects other than action in Struts 1.x

Posted by "Mahendru, Ajay" <Aj...@dishnetwork.com>.
We used thread local when we wanted something similar.. But now we have shifted to Struts 2 and so everything is on the ActionContext and hence accessible..

-----Original Message-----
From: Massimo Ugues [mailto:m.ugues@gmail.com] 
Sent: Thursday, April 07, 2011 7:25 AM
To: Struts Users Mailing List
Cc: Brian Thompson; Dave Newton
Subject: Re: Accessing session objects other than action in Struts 1.x

> I want to access session objects in a class other than Action.
You have to pass the ServletRequest object or the Session object to the instance of that class.

Mazi

On Thu, Apr 7, 2011 at 2:24 PM, Brian Thompson <el...@gmail.com>wrote:

> On Thu, Apr 7, 2011 at 7:05 AM, Dave Newton <da...@gmail.com> wrote:
>
> > On Apr 7, 2011 5:48 AM, "Ganesh" wrote:
> > > I am using Struts 1.0.2.
> >
> > Good lord why?
> >
> >
> Legacy code, I'll wager.  If he were building something brand-new, it 
> would be a no-brainer to use Struts 2.
>
> -Brian
>



--
Massimo Ugues
http://m4zi.wordpress.com/
jabber: m.ugues@gmail.com
skype: m.ugues

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


Re: Accessing session objects other than action in Struts 1.x

Posted by Dave Newton <da...@gmail.com>.
On Thu, Apr 7, 2011 at 9:25 AM, Massimo Ugues wrote:
> > I want to access session objects in a class other than Action.
> You have to pass the ServletRequest object or the Session object
> to the instance of that class.

Please don't.

Doing so ties the dependent classes to either Struts or the Servlet
spec, a dependency that is rarely required, and almost *never* a good
idea. Pass a business object, a map, or whatever instead.

Dave

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


Re: Accessing session objects other than action in Struts 1.x

Posted by Massimo Ugues <m....@gmail.com>.
> I want to access session objects in a class other than Action.
You have to pass the ServletRequest object or the Session object to the
instance of that class.

Mazi

On Thu, Apr 7, 2011 at 2:24 PM, Brian Thompson <el...@gmail.com>wrote:

> On Thu, Apr 7, 2011 at 7:05 AM, Dave Newton <da...@gmail.com> wrote:
>
> > On Apr 7, 2011 5:48 AM, "Ganesh" wrote:
> > > I am using Struts 1.0.2.
> >
> > Good lord why?
> >
> >
> Legacy code, I'll wager.  If he were building something brand-new, it would
> be a no-brainer to use Struts 2.
>
> -Brian
>



-- 
Massimo Ugues
http://m4zi.wordpress.com/
jabber: m.ugues@gmail.com
skype: m.ugues

Re: Accessing session objects other than action in Struts 1.x

Posted by Brian Thompson <el...@gmail.com>.
On Thu, Apr 7, 2011 at 7:05 AM, Dave Newton <da...@gmail.com> wrote:

> On Apr 7, 2011 5:48 AM, "Ganesh" wrote:
> > I am using Struts 1.0.2.
>
> Good lord why?
>
>
Legacy code, I'll wager.  If he were building something brand-new, it would
be a no-brainer to use Struts 2.

-Brian

Re: Accessing session objects other than action in Struts 1.x

Posted by Dave Newton <da...@gmail.com>.
On Apr 7, 2011 5:48 AM, "Ganesh" wrote:
> I am using Struts 1.0.2.

Good lord why?

> I want to access session objects in a class other than Action. Is there
any way to acheive it rather than passing the information via parameter to
each and every function?

You could create a thread local and access it via a Singleton, but that's
kind of ugly too IMO.

If you find yourself passing around the same info a lot there's a good
chance you've missed a design opportunity, though.

Dave