存储数据库连接的位置Struts 1.3中的全局变量 [英] Where to store database connection & global variables in struts 1.3
问题描述
我是Struts Java应用程序&的新手.我想存储数据库连接&全局变量. 什么是存储值的最佳选择(Web.xml或struts-config.xml). 以及如何访问该xml文件中定义的变量. 还有其他存储方式吗?访问数据库连接. 应该有办法让我可以去&轻松编辑变量和数据库连接之类的文件.
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.
推荐答案
存储数据库连接的最佳方法是
Best way to store your database connection is
- 配置数据源&应用程序服务器上的ConnectionPool.
- 利用JNDI获取数据源.
- 用于连接数据库的属性文件.
- XML文件数据库连接.
要读取属性文件,可以使用java.util.ResourceBundle
和任何XML解析器(例如X-Stream
)进行XML解析.
For reading property file you can make use of java.util.ResourceBundle
and any XML parser like X-Stream
for XML parsing.
尽管您可以使用web.xml来存储数据库连接配置参数.
Though if you want can make use of your web.xml to store database connection configuration parameters.
对于全局变量,您可以使用简单的Constant类,在其中可以定义这些变量,并可以在整个应用程序中使用它们.
For global variable you can use simple a Constant class where you can define those variable and can use them throughout your application.
这篇关于存储数据库连接的位置Struts 1.3中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!