第一种
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String absolutePath = getServletContext().getRealPath("/WEB-INF/cfg.properties");
Properties props = new Properties();
props.load(new FileInputStream(absolutePath));
System.out.println(props.getProperty("p"));
}
第二种
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ResourceBundle rb = ResourceBundle.getBundle("cfg");
String value = rb.getString("p");
System.out.println(value);
}
第三种
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream("cfg.properties");
Properties props = new Properties();
props.load(is);
System.out.println(props.getProperty("p"));
}