public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext context = this.getServletContext();
InputStream in = context.getResourceAsStream("/db.properties");
Properties prop = new Properties(); //map
prop.load(in);
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
System.out.println(url);
System.out.println(username);
System.out.println(password);
}
|
|
|
在load下面有红线,不能调用
|
|
|
直接用类加载器
|
|
| 20分 |
Properties properties = new Properties();
properties .load( 当前类.class.getClassLoader().getResourceAsStream(“db.properties”)); |
|
在load下面有红线,不能调用
这是提示你要做异常处理, |
|
|
有异常,try catch 一下
|
|
|
测试了一下,没问题
你的properties是import java.util.Propertie; 你是不是引入其他的了 |
|
| 20分 |
首先导入的包有没有问题 properties是import java.util.Propertie;
然后做异常处理 try catch |
|
为什么我的也是出现错误,异常已经抛出,引的包也是没问题的
|
|