You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Samuel Rochas <sa...@andinasoft.com> on 2004/04/28 19:15:43 UTC

Database access in contextInitialized

Hello Struts Gurus,

I am starting with struts.
I used to make some initialization in my Servlets using the init() 
method. With struts, I just implemented the contextInitialized method of 
ServletContextListener Interface, and I have a place for such 
initializations. Fine.

The things I used to initialize were some Collections with data from a 
database. With struts, I am now using the datasource configuration in 
struts-config.xml and I access it in my Actions with: 
getDataSource(request). Fine too.

But, I don't have access to getDataSource() in my ServletContextListener 
implementation. So how can I access my database there, the same way I 
access it in the rest of the application?

Thanx in advance
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------

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


Re: Reports In Struts Frame work

Posted by Kiran Kumar <mk...@yahoo.com>.
Hi,
  There is a struts-example.war that comes with Struts
, put it on ur Tomcat webapp directory and u check it
out .. it will help u understand how to go about 

Kiran

--- birendar.waldiya@tcs.com wrote:
> Hi,
> I want to implement reporting in struts framework ,
> the reports are like 
> select and display query, i dont have any idea how
> to implement then in 
> this framwork specially , the action class  for
> report , i have coded the 
> Model 1 type of jsp report can any one provide  some
> hints how to proceed 
> for action class  for report.
> thanks 
> rgds 
> 
> Birendar Singh Waldiya
> 
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

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


Re: Reports In Struts Frame work

Posted by bi...@tcs.com.
ok , thanks !

Birendar Singh Waldiya




as as <sa...@yahoo.com> 
11-05-04 01:32 AM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
Struts Users Mailing List <us...@struts.apache.org>
cc

Subject
Re: Reports In  Struts Frame work






did u try jfree.org
have a look at jchart.org also

birendar.waldiya@tcs.com wrote:

Hi, 
I want to implement reporting in struts framework , the reports are like 
select and display query, i dont have any idea how to implement then in 
this framwork specially , the action class  for report , i have coded the 
Model 1 type of jsp report can any one provide  some hints how to proceed 
for action class  for report. 
thanks 
rgds 

Birendar Singh Waldiya



"Jonathan Wright" <jo...@aboutit.co.nz> 
29-04-04 10:16 AM 
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"Struts Users Mailing List" <us...@struts.apache.org> cc
Subject
Re: Database access in contextInitialized




The 'dataSource' attribute is stored in your servlet context. So anywhere
you can get a reference to that you can get hold of a reference to your 
data
source.

Hope that helps!

Jonathan

----- Original Message -----
From: "Samuel Rochas" <sa...@andinasoft.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, April 29, 2004 5:15 AM
Subject: Database access in contextInitialized


> Hello Struts Gurus,
>
> I am starting with struts.
> I used to make some initialization in my Servlets using the init()
> method. With struts, I just implemented the contextInitialized method of
> ServletContextListener Interface, and I have a place for such
> initializations. Fine.
>
> The things I used to initialize were some Collections with data from a
> database. With struts, I am now using the datasource configuration in
> struts-config.xml and I access it in my Actions with:
> getDataSource(request). Fine too.
>
> But, I don't have access to getDataSource() in my ServletContextListener
> implementation. So how can I access my database there, the same way I
> access it in the rest of the application?
>
> Thanx in advance
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.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


ForwardSourceID:NT00006246 
DISCLAIMER: The information contained in this message is intended only and 
solely for the addressed individual or entity indicated in this message 
and for the exclusive use of the said addressed individual or entity 
indicated in this message (or responsible for delivery
of the message to such person) and may contain legally privileged and 
confidential information belonging to Tata Consultancy Services. It must 
not be printed, read, copied, disclosed, forwarded, distributed or used 
(in whatsoever manner) by any person other than the addressee. 
Unauthorized use, disclosure or copying is strictly prohibited and may 
constitute unlawful act and can possibly attract legal action, civil 
and/or criminal. The contents of this message need not necessarily reflect 
or endorse the views of Tata Consultancy Services on any subject matter.
Any action taken or omitted to be taken based on this message is entirely 
at your risk and neither the originator of this message nor Tata 
Consultancy Services takes any responsibility or liability towards the 
same. Opinions, conclusions and any other information contained in this 
message 
that do not relate to the official business of Tata Consultancy Services 
shall be understood as neither given nor endorsed by Tata Consultancy 
Services or any affiliate of Tata Consultancy Services. If you have 
received this message in error, you should destroy this message and may 
please notify the sender by e-mail. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
 
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 
ForwardSourceID:NT000085F2 

Re: Reports In Struts Frame work

Posted by as as <sa...@yahoo.com>.
did u try jfree.org
have a look at jchart.org also

birendar.waldiya@tcs.com wrote:

Hi, 
I want to implement reporting in struts framework , the reports are like  select and display query, i dont have any idea how to implement then in this framwork specially , the action class  for report , i have coded the Model 1 type of jsp report can any one provide  some hints how to proceed for action class  for report. 
thanks 
rgds 

Birendar Singh Waldiya



"Jonathan Wright" <jo...@aboutit.co.nz> 
29-04-04 10:16 AM 
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"Struts Users Mailing List" <us...@struts.apache.org> cc
Subject
Re: Database access in contextInitialized




The 'dataSource' attribute is stored in your servlet context. So anywhere
you can get a reference to that you can get hold of a reference to your data
source.

Hope that helps!

Jonathan

----- Original Message -----
From: "Samuel Rochas" <sa...@andinasoft.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, April 29, 2004 5:15 AM
Subject: Database access in contextInitialized


> Hello Struts Gurus,
>
> I am starting with struts.
> I used to make some initialization in my Servlets using the init()
> method. With struts, I just implemented the contextInitialized method of
> ServletContextListener Interface, and I have a place for such
> initializations. Fine.
>
> The things I used to initialize were some Collections with data from a
> database. With struts, I am now using the datasource configuration in
> struts-config.xml and I access it in my Actions with:
> getDataSource(request). Fine too.
>
> But, I don't have access to getDataSource() in my ServletContextListener
> implementation. So how can I access my database there, the same way I
> access it in the rest of the application?
>
> Thanx in advance
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.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


ForwardSourceID:NT00006246     
DISCLAIMER: The information contained in this message is intended only and solely for the addressed individual or entity indicated in this message and for the exclusive use of the said addressed individual or entity indicated in this message (or responsible for delivery
of the message to such person) and may contain legally privileged and confidential information belonging to Tata Consultancy Services. It must not be printed, read, copied, disclosed, forwarded, distributed or used (in whatsoever manner) by any person other than the addressee. 
Unauthorized use, disclosure or copying is strictly prohibited and may constitute unlawful act and can possibly attract legal action, civil and/or criminal. The contents of this message need not necessarily reflect or endorse the views of Tata Consultancy Services on any subject matter.
Any action taken or omitted to be taken based on this message is entirely at your risk and neither the originator of this message nor Tata Consultancy Services takes any responsibility or liability towards the same. Opinions, conclusions and any other information contained in this message 
that do not relate to the official business of Tata Consultancy Services shall be understood as neither given nor endorsed by Tata Consultancy Services or any affiliate of Tata Consultancy Services. If you have received this message in error, you should destroy this message and may please notify the sender by e-mail. Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
		
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

Reports In Struts Frame work

Posted by bi...@tcs.com.
Hi,
I want to implement reporting in struts framework , the reports are like 
select and display query, i dont have any idea how to implement then in 
this framwork specially , the action class  for report , i have coded the 
Model 1 type of jsp report can any one provide  some hints how to proceed 
for action class  for report.
thanks 
rgds 

Birendar Singh Waldiya




"Jonathan Wright" <jo...@aboutit.co.nz> 
29-04-04 10:16 AM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"Struts Users Mailing List" <us...@struts.apache.org>
cc

Subject
Re: Database access in contextInitialized






The 'dataSource' attribute is stored in your servlet context. So anywhere
you can get a reference to that you can get hold of a reference to your 
data
source.

Hope that helps!

Jonathan

----- Original Message -----
From: "Samuel Rochas" <sa...@andinasoft.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, April 29, 2004 5:15 AM
Subject: Database access in contextInitialized


> Hello Struts Gurus,
>
> I am starting with struts.
> I used to make some initialization in my Servlets using the init()
> method. With struts, I just implemented the contextInitialized method of
> ServletContextListener Interface, and I have a place for such
> initializations. Fine.
>
> The things I used to initialize were some Collections with data from a
> database. With struts, I am now using the datasource configuration in
> struts-config.xml and I access it in my Actions with:
> getDataSource(request). Fine too.
>
> But, I don't have access to getDataSource() in my ServletContextListener
> implementation. So how can I access my database there, the same way I
> access it in the rest of the application?
>
> Thanx in advance
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.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


ForwardSourceID:NT00006246 

Re: Database access in contextInitialized

Posted by Jonathan Wright <jo...@aboutit.co.nz>.
The 'dataSource' attribute is stored in your servlet context. So anywhere
you can get a reference to that you can get hold of a reference to your data
source.

Hope that helps!

Jonathan

----- Original Message -----
From: "Samuel Rochas" <sa...@andinasoft.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, April 29, 2004 5:15 AM
Subject: Database access in contextInitialized


> Hello Struts Gurus,
>
> I am starting with struts.
> I used to make some initialization in my Servlets using the init()
> method. With struts, I just implemented the contextInitialized method of
> ServletContextListener Interface, and I have a place for such
> initializations. Fine.
>
> The things I used to initialize were some Collections with data from a
> database. With struts, I am now using the datasource configuration in
> struts-config.xml and I access it in my Actions with:
> getDataSource(request). Fine too.
>
> But, I don't have access to getDataSource() in my ServletContextListener
> implementation. So how can I access my database there, the same way I
> access it in the rest of the application?
>
> Thanx in advance
> Samuel
>
> ---  andinasoft SA - Software y Consulting  ---
> Mariano Aguilera 276 y Almagro - Quito, Ecuador
> Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
> ---------  http://www.andinasoft.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


Re: Database access in contextInitialized

Posted by Richard Yee <ry...@cruzio.com>.
Craig,
When I put logging statements in the ServletContextInitializer class, I see 
that the ServletContextInitializer.contextInitialized() method is actually 
called after the servlet init() methods for servlets that load at startup. 
Is this correct? You say that the contextInitialized() gets called before 
the ActionServlet.init() method is called.

Thanks,

Richard


At 09:59 PM 5/1/2004, you wrote:
>Samuel Rochas wrote:
>
>>Hello Struts Gurus,
>>
>>I am starting with struts.
>>I used to make some initialization in my Servlets using the init() 
>>method. With struts, I just implemented the contextInitialized method of 
>>ServletContextListener Interface, and I have a place for such 
>>initializations. Fine.
>>
>>The things I used to initialize were some Collections with data from a 
>>database. With struts, I am now using the datasource configuration in 
>>struts-config.xml and I access it in my Actions with: 
>>getDataSource(request). Fine too.
>>
>>But, I don't have access to getDataSource() in my ServletContextListener 
>>implementation. So how can I access my database there, the same way I 
>>access it in the rest of the application?
>
>
>The problem, as you've undoubtedly discovered, is that your 
>ServletContextListener gets invoked before the ActionServlet.init() method 
>has had a chance to run, so the Struts initialization has not yet been 
>performed.  This makes perfect sense when you understand that Struts was 
>created to run on top of Servlet 2.2, before there was such a thing as a 
>ServletContextListener.
>
>Indeed, the recommended pattern today is for you to acquire your 
>DataSource instances from the JNDI naming context (configured by your app 
>server's admin console), rather than configuring them inside the 
>webapp.  The getDataSource() method, and everything about Struts-provided 
>connection pools, has been deprecated but remains only for backwards 
>compatibility purposes.
>
>If it is too painful to switch to JNDI-provided data sources in the short 
>run, then you should do your initialization in a Struts PlugIn instead of 
>using a ServletContextListener.  These are executed after the 
>Struts-defined data sources have been created, so they will be available 
>to you during your initialization.
>
>But you should really really switch to JNDI-provided data sources if they 
>are supported by your container.
>
>Craig McClanahan
>
>
>
>---------------------------------------------------------------------
>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: Database access in contextInitialized

Posted by Samuel Rochas <sa...@andinasoft.com>.
Hello Craig,

> Indeed, the recommended pattern today is for you to acquire your 
> DataSource instances from the JNDI naming context
Thanks for your advise. I was the way I handled it before using struts, 
so I will continue that way.

Sincerly
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------


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


Re: Database access in contextInitialized

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Samuel Rochas wrote:

> Hello Struts Gurus,
>
> I am starting with struts.
> I used to make some initialization in my Servlets using the init() 
> method. With struts, I just implemented the contextInitialized method 
> of ServletContextListener Interface, and I have a place for such 
> initializations. Fine.
>
> The things I used to initialize were some Collections with data from a 
> database. With struts, I am now using the datasource configuration in 
> struts-config.xml and I access it in my Actions with: 
> getDataSource(request). Fine too.
>
> But, I don't have access to getDataSource() in my 
> ServletContextListener implementation. So how can I access my database 
> there, the same way I access it in the rest of the application? 


The problem, as you've undoubtedly discovered, is that your 
ServletContextListener gets invoked before the ActionServlet.init() 
method has had a chance to run, so the Struts initialization has not yet 
been performed.  This makes perfect sense when you understand that 
Struts was created to run on top of Servlet 2.2, before there was such a 
thing as a ServletContextListener.

Indeed, the recommended pattern today is for you to acquire your 
DataSource instances from the JNDI naming context (configured by your 
app server's admin console), rather than configuring them inside the 
webapp.  The getDataSource() method, and everything about 
Struts-provided connection pools, has been deprecated but remains only 
for backwards compatibility purposes.

If it is too painful to switch to JNDI-provided data sources in the 
short run, then you should do your initialization in a Struts PlugIn 
instead of using a ServletContextListener.  These are executed after the 
Struts-defined data sources have been created, so they will be available 
to you during your initialization.

But you should really really switch to JNDI-provided data sources if 
they are supported by your container.

Craig McClanahan



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