jsp 从web.xml读取连接数据库的参数
程序员文章站
2023-12-01 09:08:34
jsp或servlet页面代码:复制代码 代码如下:string driver = application. getini tparameter ("driver") ;...
jsp或servlet页面代码:
string driver = application. getini tparameter ("driver") ;
string url = application.getinitparameter("url");
string user = application.getinitparameter("user");
string pass = application.getinitparameter("pass");
web.xml需要读取的内容:
<context-param>
<param-name>driver</param-name>
<param-value>com.mysql.jdbc.driver</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost:3306/j2ee</param-value>
</context-param>
<context-param>
<param-name>user</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>pass</param-name>
<param-value>32l47</param-value>
</context-param>
复制代码 代码如下:
string driver = application. getini tparameter ("driver") ;
string url = application.getinitparameter("url");
string user = application.getinitparameter("user");
string pass = application.getinitparameter("pass");
web.xml需要读取的内容:
复制代码 代码如下:
<context-param>
<param-name>driver</param-name>
<param-value>com.mysql.jdbc.driver</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost:3306/j2ee</param-value>
</context-param>
<context-param>
<param-name>user</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>pass</param-name>
<param-value>32l47</param-value>
</context-param>