Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Clarification of Concept: DataSource of Struts

Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am learning Struts so appreciate if someone can clarify if my understanding is correct:

(1) <data-sources> element of struts-config.xml is to config a datasource managed by struts internally and is INDEPENDENT OF Tomcat. So if we specify:
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="oracle.jdbc.OracleDriver" />
<set-property property="url" value="jdbc racle:thin:@myhost:1521 DB" />
<set-property property="username" value="scott"/>
<set-property property="password" value="tiger"/>

then the datasource is Jakarta's dbcp connection pooling which provides connection pooling independent of Tomcat.

(2) We can also use Tomcat to provide connection pooling. In that case we dont need to use <data-sources> in struts-config.xml at all. Instead, we use JNDI in each Action to lookup a datasource and get the connection. The connection so returned is transparently pooled.

Are my 2 points above correct?
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mostly correct.

If people are deploying Struts applications into full-blown J2EE containers, most won't have access to the sort of files you'd edit to create DataSources in Tomcat. If all you have is access to web.xml in your WEB-INF directory, all you'll be able to do is create a reference to an existing DataSource.

So ... if you don't have the DataSource, the web.xml won't be much use to you. Ergo, you'd end up doing it in the struts-config.xml file instead. The use of this just depends on what you have access to. I'm not sure what the benefits of doing the config within the struts-config.xml file is if you can configure the DataSource through the web container instead. I suppose it would hinge on whether you had some need that the web container couldn't do that struts-config.xml could do.

I'm rambling, but I hope that helps.
    Bookmark Topic Watch Topic
  • New Topic