问题描述
代码:
InputStream is = this.getServletContext().getResourceAsStream("/WEB-INF/classes/com/db.properties"); Properties prop = new Properties(); prop.load(is); String user = prop.getProperty("username"); String pwd = prop.getProperty("password"); resp.getWriter().print(user +":" + pwd);
原因分析:
百度原因说可能是properties配置文件没放到resource里面,但我的是放在resource里的,后面监察发现,我的路径多写了com
解决方案:
InputStream is = this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties"); Properties prop = new Properties(); prop.load(is); String user = prop.getProperty("username"); String pwd = prop.getProperty("password"); resp.getWriter().print(user +":" + pwd);
把com路径删除