File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Clarification of Concept: DataSource of Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Clarification of Concept: DataSource of Struts" Watch "Clarification of Concept: DataSource of Struts" New topic

Clarification of Concept: DataSource of Struts

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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?
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.

I agree. Here's the link:
subject: Clarification of Concept: DataSource of Struts
jQuery in Action, 3rd edition