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");

最新文章

  1. [翻译]AKKA笔记 - DEATHWATCH -7
  2. Java 如何跳出多重嵌套循环体?
  3. Mob.com 短信验证的简单使用
  4. android studio 注释模板
  5. GC是什么? 为什么要有GC?
  6. XAF应用开发教程(七)外观控制模块
  7. java线程实践记录
  8. UVa 400 (水题) Unix ls
  9. Python爬虫学习:四、headers和data的获取
  10. 【转】commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar实现文件上传
  11. zoj 3708 Density of Power Network
  12. python编程基础知识—列表(二)
  13. CentOS7卸载自带jdk安装自己的JDK1.8
  14. day 05字典相关内容
  15. 用Python对html进行编码
  16. laravel简书(2)
  17. jdk8 tomcat7
  18. 使用Beetle简单构建聊天室程序
  19. mysql不能启动报error2013错误的解决办法
  20. EF4.1 企业架构模式 自动映射数据表(转载)

热门文章

  1. caffe: compile error : undefined reference to `cv::imread(cv::String const&amp;, int)&#39; et al.
  2. ascii codec can&#39;t decode byte 0xe8 in position 0:ordinal not in range(128)
  3. Cannot unwrap to requested type [javax.sql.DataSource]
  4. linux服务之openldap
  5. linux包之e2fsprogs之chattr命令
  6. wamp下Apache2.4.x局域网访问403的解决办法
  7. Python 2.x与3.x共存
  8. Reporting Service 报表报 rsReportServerDatabaseError 错的解决方法
  9. openstack(liberty): devstack之screen
  10. CCS float vs clear