可能重复:
如何将.properties文件加载到jsp中
我正在尝试在JSP中使用我的属性文件,但无法正常工作并引发错误
Error: myproperties.properties (The system cannot find the file specified)
在这里,我试图访问我的属性文件:
<%
try
{
FileInputStream fis = new FileInputStream("myproperties.properties");
Properties p = new Properties();
p.load(fis);
String LogFileName = p.getProperty("NameOfLogFile");
out.println(LogFileName);
}
catch (Exception e)
{// Catch exception if any
out.println(e.getMessage());
}
我已经尝试了多种方法来访问属性文件。我该如何解决?
在您的包中创建test.properties文件
pname=xyz
psurname=abc
创建jsp文件:
<%@ page language="java" import="java.util.*" %>
<%@ page import = "java.util.ResourceBundle" %>
<% ResourceBundle resource = ResourceBundle.getBundle("test");
String name=resource.getString("pname");
String surname=resource.getString("psurname"); %>
<%=name %>
<%=surname%>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句