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-sources> <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"/> </data-source> </data-sources>
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?
Joined: May 29, 2003
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.