?
?
?
?
?
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ServletContext context = this.getServletContext();
InputStream inputStream = context.getResourceAsStream("aa.properties");
Properties pro = new Properties();
pro.load(inputStream);
String user = pro.getProperty("username");
String pwd = pro.getProperty("password");
resp.getWriter().print(user + ": " + pwd);
}
?
?如果路径直接使用aa.properties会出现空指针现象,无法正常调用配置文件,需要将其修改为
InputStream inputStream = context.getResourceAsStream("/WEB-INF/classes/aa.properties");
既调用target目录下生成的aa.properties配置文件,这个target目录默认是不可见的,可以通过Project Srtucture-Modules-当前项目-target-Excluded-Apply-OK使其显示
?
|