欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp 从web.xml读取连接数据库的参数

程序员文章站 2024-02-18 00:01:04
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>