【发布时间】:2014-11-23 16:40:47
【问题描述】:
我有数据源,代码如下:
public class DataSource {
Connection connection = null;
BasicDataSource bdsource = new BasicDataSource();
public DataSource() {
bdsource.setDriverClassName("com.mysql.jdbc.Driver");
bdsource.setUrl("jdbc:mysql://localhost:3306/databaseName");
bdsource.setUsername("UserName");
bdsource.setPassword("PassWord");
}
public Connection createConnection() {
Connection con = null;
try {
if (connection != null) {
System.out.println("Can't create a new connection");
} else {
con = bdsource.getConnection();
}
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
我需要在 jsp 上显示一些来自数据库的数据。那么如何在 jsp 中设置数据源而不让世界知道 jsp 中的用户名、密码和数据库名称呢?
【问题讨论】:
-
无论如何,在您使用 JSP 打印之前,没有人能够看到您的用户名、数据源中的密码
-
但他们可以访问我的 jsp 页面本身没有.. 通常将所有这些都保存在 jsp 中不是一个好习惯。从堆栈本身学到的