I am new to struts java application & i want to store database connections & global variables. What is best option to store values (Web.xml or struts-config.xml). and How to access the variables defined in that xml files. Is there any other way to store & access database connections. There should be way so that i can go & edit the files like variables and databases connections easily.
Asked
Active
Viewed 1,634 times
1 Answers
3
Best way to store your database connection is
- Configure DataSource & ConnectionPool on application server.
- Make use of JNDI to obtain DataSource.
- Properties file for database connectivity.
- XML file database connectivity.
For reading property file you can make use of java.util.ResourceBundle
and any XML parser like X-Stream
for XML parsing.
Though if you want can make use of your web.xml to store database connection configuration parameters.
For global variable you can use simple a Constant class where you can define those variable and can use them throughout your application.

Umesh Awasthi
- 23,407
- 37
- 132
- 204
-
Is there any other way to access properties file rather than resource bundle. – Coder Guru Feb 06 '12 at 12:27
-
use file IO if you don't want to use resource bundle – Umesh Awasthi Feb 06 '12 at 12:34
-
follow this good tutorial on the java world http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html – Umesh Awasthi Feb 06 '12 at 12:46
-
How to access resource file if it is in the WEB-INF folder – Coder Guru Feb 06 '12 at 12:55