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

这是一篇很有收藏价值的文章《javascriptp 从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>

本文javascriptp 从web.xml读取连接数据库的参数到此结束。青春的幻想既狂热又可爱。小编再次感谢大家对我们的支持!