我正在尝试在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%>