首页 > 编程 > JSP > 正文

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

2024-09-05 00:21:14
字体:
来源:转载
供稿:网友
web.xml读取连接数据库的参数,实现代码。

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>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表