可能重复:
如何将.properties文件加载到jsp中
我试图在JSP中使用我的属性文件,但它无法正常工作并抛出错误
Error: myproperties.properties (The system cannot find the file specified)
Run Code Online (Sandbox Code Playgroud)
在这里,我试图访问我的属性文件:
<%
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());
}
Run Code Online (Sandbox Code Playgroud)
我已经通过多种方式尝试访问属性文件.我该如何解决?
我的JSP页面需要根据它们所处的环境(开发,生产,沙箱等)显示不同的信息.我希望每个环境都有一个属性文件,其中包含它们可能需要的所有参数.如何在JSP页面中引用此文件的属性?
我的想法是:
更新 - 我应该提到我使用的是Spring 3.0和Spring webmvc.所以,如果有一些最好的实践方法,使用Spring做到这一点,这是理想的!