public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

          //1.获取资源文件          
          InputStream is=this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");


        String value="aaaa";
        this.getServletContext().setAttribute("data", value);
        request.setAttribute("value", value);
        this.getServletContext().getRequestDispatcher("/1.jsp").forward(request, response);
    }

1.jsp

 

<body>
<%
String value = (String) request.getAttribute("value");
String data = (String) application.getAttribute("data");
out.write("data:" + data);


out.write("value:" + value);
%>
This is my JSP page.
<br>
</body>
</html>

 

 

获取配置文件

InputStream is = this.getServletContext().getResourceAsStream( "/WEB-INF/classes/db.properties");

Properties prop = new Properties(); prop.load(is);

String url = prop.getProperty("dburl");

String username = prop.getProperty("username");

String password = prop.getProperty("password");

System.out.println(url + " " + username + " " + password);

 

//获取硬盘上的实际路径

String db = this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");

相关文章:

  • 2022-12-23
  • 2021-08-13
  • 2021-12-02
  • 2022-12-23
  • 2021-06-24
  • 2021-11-03
  • 2021-12-07
  • 2022-01-26
猜你喜欢
  • 2021-10-10
  • 2021-09-03
  • 2022-12-23
  • 2021-08-23
  • 2021-06-18
  • 2022-12-23
相关资源
相似解决方案