Shun 发表于 2021-10-24 13:12:11

jsp 从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>

https://www.uoften.com/program/jsp/20180413/47535.html
页: [1]
查看完整版本: jsp 从web.xml读取连接数据库的参数