You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Raquepo <rr...@primeorion.com> on 2003/06/30 08:21:37 UTC

using struts datasource from a servlet

can i call/use the a struts datasource in my servlet.

the thing is, i have a struts app. then i created a servlet to do some specific thing. now my question is,
can i use the datasource defined in my struts config file in my servlet. if so, how? example code will
be very much appreciated.

thanks.

-richard

Re: using struts datasource from a servlet

Posted by Erik Price <ep...@ptc.com>.

Richard Raquepo wrote:
>>Another option would be to configure the DS in struts but register it with
> 
> a
> 
>>singleton (Service Locator) that can retrieve the datasource in your data
>>access classes.
> 
> 
> maybe you can give me some link about this? tutorials maybe? any code maybe?
> :p

As you wish:

<http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html>


Erik


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


Re: using struts datasource from a servlet

Posted by Richard Raquepo <rr...@primeorion.com>.
> Another option would be to configure the DS in struts but register it with
a
> singleton (Service Locator) that can retrieve the datasource in your data
> access classes.

maybe you can give me some link about this? tutorials maybe? any code maybe?
:p

thanks a lot.

----- Original Message -----
From: "Steve Raeburn" <st...@ninsky.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, June 30, 2003 3:20 PM
Subject: RE: using struts datasource from a servlet


> You can either pass the datasource from your servlet/action as a method
> parameter or you need to register the datasource somewhere that the class
> can access.
>
> That might be using JNDI, in which case you probably don't need to
configure
> your datasource in Struts but in your container.
>
> Another option would be to configure the DS in struts but register it with
a
> singleton (Service Locator) that can retrieve the datasource in your data
> access classes.
>
> Steve
>
> > -----Original Message-----
> > From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> > Sent: June 29, 2003 11:54 PM
> > To: Struts Users Mailing List; steve@ninsky.com
> > Subject: Re: using struts datasource from a servlet
> >
> >
> > ic... another question.
> > what if it's not a servlet. just a class i made wherein i call it from
one
> > of my action or servlet
> > but still i will need to use struts datasource. how can it be done.
> >
> > thanks everyone.
> >
> > -richard
> >
> > ----- Original Message -----
> > From: "Steve Raeburn" <st...@ninsky.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Monday, June 30, 2003 2:34 PM
> > Subject: RE: using struts datasource from a servlet
> >
> >
> > > Struts stores the datasources as servlet context attributes.
> > >
> > > You can access the default datasource in your servlet using -
> > >
> > > (DataSource)
getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
> > >
> > > Take a look at the struts-config dtd for more info (particularly if
you
> > use
> > > modules)
> > > http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd
> > >
> > > Steve
> > >
> > > > -----Original Message-----
> > > > From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> > > > Sent: June 29, 2003 11:22 PM
> > > > To: Struts Users Mailing List
> > > > Subject: using struts datasource from a servlet
> > > >
> > > >
> > > > can i call/use the a struts datasource in my servlet.
> > > >
> > > > the thing is, i have a struts app. then i created a servlet to do
> > > > some specific thing. now my question is,
> > > > can i use the datasource defined in my struts config file in my
> > > > servlet. if so, how? example code will
> > > > be very much appreciated.
> > > >
> > > > thanks.
> > > >
> > > > -richard
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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


RE: using struts datasource from a servlet

Posted by Steve Raeburn <st...@ninsky.com>.
You can either pass the datasource from your servlet/action as a method
parameter or you need to register the datasource somewhere that the class
can access.

That might be using JNDI, in which case you probably don't need to configure
your datasource in Struts but in your container.

Another option would be to configure the DS in struts but register it with a
singleton (Service Locator) that can retrieve the datasource in your data
access classes.

Steve

> -----Original Message-----
> From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> Sent: June 29, 2003 11:54 PM
> To: Struts Users Mailing List; steve@ninsky.com
> Subject: Re: using struts datasource from a servlet
>
>
> ic... another question.
> what if it's not a servlet. just a class i made wherein i call it from one
> of my action or servlet
> but still i will need to use struts datasource. how can it be done.
>
> thanks everyone.
>
> -richard
>
> ----- Original Message -----
> From: "Steve Raeburn" <st...@ninsky.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Monday, June 30, 2003 2:34 PM
> Subject: RE: using struts datasource from a servlet
>
>
> > Struts stores the datasources as servlet context attributes.
> >
> > You can access the default datasource in your servlet using -
> >
> > (DataSource) getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
> >
> > Take a look at the struts-config dtd for more info (particularly if you
> use
> > modules)
> > http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd
> >
> > Steve
> >
> > > -----Original Message-----
> > > From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> > > Sent: June 29, 2003 11:22 PM
> > > To: Struts Users Mailing List
> > > Subject: using struts datasource from a servlet
> > >
> > >
> > > can i call/use the a struts datasource in my servlet.
> > >
> > > the thing is, i have a struts app. then i created a servlet to do
> > > some specific thing. now my question is,
> > > can i use the datasource defined in my struts config file in my
> > > servlet. if so, how? example code will
> > > be very much appreciated.
> > >
> > > thanks.
> > >
> > > -richard
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>



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


Re: using struts datasource from a servlet

Posted by Richard Raquepo <rr...@primeorion.com>.
ic... another question.
what if it's not a servlet. just a class i made wherein i call it from one
of my action or servlet
but still i will need to use struts datasource. how can it be done.

thanks everyone.

-richard

----- Original Message -----
From: "Steve Raeburn" <st...@ninsky.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, June 30, 2003 2:34 PM
Subject: RE: using struts datasource from a servlet


> Struts stores the datasources as servlet context attributes.
>
> You can access the default datasource in your servlet using -
>
> (DataSource) getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
>
> Take a look at the struts-config dtd for more info (particularly if you
use
> modules)
> http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd
>
> Steve
>
> > -----Original Message-----
> > From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> > Sent: June 29, 2003 11:22 PM
> > To: Struts Users Mailing List
> > Subject: using struts datasource from a servlet
> >
> >
> > can i call/use the a struts datasource in my servlet.
> >
> > the thing is, i have a struts app. then i created a servlet to do
> > some specific thing. now my question is,
> > can i use the datasource defined in my struts config file in my
> > servlet. if so, how? example code will
> > be very much appreciated.
> >
> > thanks.
> >
> > -richard
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



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


RE: using struts datasource from a servlet

Posted by Steve Raeburn <st...@ninsky.com>.
Struts stores the datasources as servlet context attributes.

You can access the default datasource in your servlet using -

	(DataSource) getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);

Take a look at the struts-config dtd for more info (particularly if you use
modules)
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd

Steve

> -----Original Message-----
> From: Richard Raquepo [mailto:rraquepo@primeorion.com]
> Sent: June 29, 2003 11:22 PM
> To: Struts Users Mailing List
> Subject: using struts datasource from a servlet
>
>
> can i call/use the a struts datasource in my servlet.
>
> the thing is, i have a struts app. then i created a servlet to do
> some specific thing. now my question is,
> can i use the datasource defined in my struts config file in my
> servlet. if so, how? example code will
> be very much appreciated.
>
> thanks.
>
> -richard



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