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);
}
------解决思路----------------------
Properties properties = new Properties();
properties .load( 当前类.class.getClassLoader().getResourceAsStream("db.properties"));
------解决思路----------------------
首先导入的包有没有问题 properties是import java.util.Propertie;
然后做异常处理 try catch