jsp页面的使用
? ? ? ? ? //1.獲取資源文件 ? ? ? ? ?
? ? ? ? ? InputStream is=this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
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");
轉載于:https://www.cnblogs.com/zhuawang/p/3395410.html
總結
- 上一篇: java数组实验心得体会_JAVA实验报
- 下一篇: 工欲善其事必先利其器系列之:在VS里面折