Search code examples
javastrutsweb.xmlstruts-1struts-config

Where to store database connection & global variables in struts 1.3


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.


Solution

  • Best way to store your database connection is

    1. Configure DataSource & ConnectionPool on application server.
    2. Make use of JNDI to obtain DataSource.
    3. Properties file for database connectivity.
    4. 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.