在servlet中通过servletcontext对象读取资源文件的模板代码
来源:互联网 发布:word文档归类软件 编辑:程序博客网 时间:2024/04/28 06:26
在servlet中有时需要读取资源文件中的一些相关的信息,例如在资源文件中可能会实现配置数据库有关的信息,这时就可以通过servletcontext对象读取资源文件的相关的信息。具体的代码如下所示:
private void test() throws IOException { InputStream in = this.getServletContext().getResourceAsStream("/db.properties"); Properties p=new Properties(); p.load(in); String driver=p.getProperty("driver"); String username=p.getProperty("username"); String password=p.getProperty("password"); String url=p.getProperty("url"); System.out.println(username); System.out.println(password); System.out.println(url); System.out.println(driver); }
0 0
- 在servlet中通过servletcontext对象读取资源文件的模板代码
- web项目中servlet利用servletContext对象读取资源文件
- ServletContext对象读取资源文件
- (18)servletContext应用:获取web应用的初始化参数、实现servlet转发、利用servletContext对象读取资源文件
- ServletContext读取资源文件
- Servlet之ServletContext读取web应用中的资源文件
- servlet 的servletContext 对象
- 04.ServletContext读取资源文件
- servletcontext读取web资源文件
- 使用servletContext读取资源文件
- Spring中ApplicationContextAware实现获取bean的工具类,在servlet中通过servletContext获取application
- Spring MVC中,通过Java代码读取资源文件时,发生乱码的解决方法
- ServletContext对象读取资源路径的三种方式
- Servlet之ServletContext获取获取web项目的资源文件
- ServletContext读取Web应用下的文件资源
- 用ServletContext读取资源文件的三种方式
- 在servlet和非servlet实体类中如何读取资源文件
- J2EE之ServletContext读取资源文件
- 通过实例来学习使用Linux KVM
- Struts2.3.14路由分析
- 安卓学习第二十二天:ProgressBar与SeekBar与RatingBar
- POJ2653——Pick-up sticks
- 字符串匹配的KMP算法
- 在servlet中通过servletcontext对象读取资源文件的模板代码
- 11g新特性:A useful View V$DIAG_INFO
- 2012年写的万年历
- Uva 10375
- Insertion-sort
- vs2005下载网页图片
- C++中的关键字 volatile 详解
- OpenGL编程逐步深入(十一)组合变换
- UVALive_6843_Volume Control(暴力+标记)