大神们,为什么我的web应用不能调用Properties的load方法

J2EE 码拜 9年前 (2015-05-10) 1575次浏览 0个评论
 
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 就好了

有异常,try   catch  一下
测试了一下,没问题
你的properties是import java.util.Propertie;
你是不是引入其他的了
20分
首先导入的包有没有问题  properties是import java.util.Propertie;
然后做异常处理 try catch
为什么我的也是出现错误,异常已经抛出,引的包也是没问题的大神们,为什么我的web应用不能调用Properties的load方法,报错位置为大神们,为什么我的web应用不能调用Properties的load方法

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明大神们,为什么我的web应用不能调用Properties的load方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!