在servlet通过xml文件访问properties文件
来源:互联网 发布:淘宝上组装电脑 编辑:程序博客网 时间:2024/06/07 15:37
servlet代码
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {ServletConfig cfg = this.getServletConfig();//读取web.xml文件
String filename = cfg.getInitParameter("config");//找到servlet中对应的参数名
String path = this.getServletContext().getRealPath("/");// 返回Servlet上下文路径
path = path.substring(0, path.length() - 1);// 在Servlet上下文路径的最后包含一个"."号,所以这里将它去除
path = path + filename;
FileInputStream input = new FileInputStream(path);
Properties prop= new Properties();
prop.load(input);
String name= prop.getProperty("name");// 获取name的值
}
web.xml代码
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>CheckUser</servlet-name>
<servlet-class>CheckUser</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/config.properties</param-value>
</init-param>
</servlet>
config.properties代码
name=admin
0 0
- 在servlet通过xml文件访问properties文件
- 通过ajax访问xml文件
- servlet读取properties文件
- 通过Properties读写文件
- 通过反射访问根目录下XML文件
- php通过SAX访问xml文件
- php通过xpath访问xml文件
- Properties读取xml文件
- xml 引入properties文件
- properties文件转xml
- [XML与properties文件]
- Servlet在web.xml文件中的部署
- Servlet读取properties资源文件
- Servlet:通过初始参数实现权限访问某个文件、页面
- 通过.properties文件配置参数
- java访问资源文件Properties
- java访问资源文件 .properties
- 在applicationContext.xml中引入jdbc.properties文件
- STM32 寄存器库和固件库
- com.microsoft.sqlserver.jdbc.SQLServerException:该语句没有返回结果集
- 可编辑的select 框
- pl sql 学习笔记(六)再学动态sql
- js四舍五入(round()方法)并保留小数点后N位的函数
- 在servlet通过xml文件访问properties文件
- xxx
- 项目经验:clear清除浮动样式
- uvalive3942(字典树)
- 一个C源文件到可执行文件 [反汇编-函数栈帧 编译 链接]
- java中的引用类型
- 正则非贪婪匹配 及 容易出现的错误
- USB Class Codes
- 不要做一个浮躁的程序员