Where to store database connection & global variables in struts 1.3

旧街凉风 提交于 2019-12-25 00:48:33

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9159831/where-to-store-database-connection-global-variables-in-struts-1-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!