如何将.properties文件加载到jsp中

如何将.properties文件加载到jsp中

问题描述:

我已经达到了这个目的:

I've gotten as far as this:

private Properties logoUrls = new Properties();
logoUrls.load(new FileInputStream("channelLogos.properties"));

其中channelLogos.properties与我的JSP位于同一目录中。我得到一个FileNotFound异常。我的应用程序实际上认为我的意思是channelLogos.properties,如果不是与JSP相同的目录?如何确定加载属性文件的正确路径?

where channelLogos.properties is in the same directory as my JSP. I get a FileNotFound exception. Where does my app actually think I mean by "channelLogos.properties", if not the same directory as the JSP? How can I determine the correct path to load the properties file?

这将完成工作:

<%@page import="java.io.InputStream" %>
<%@page import="java.util.Properties" %>

<%
    InputStream stream = application.getResourceAsStream("/some.properties");
    Properties props = new Properties();
    props.load(stream);
%>

无论如何,我真的认为你应该在 classpath 中拥有属性文件使用servlet

Anyway I really think you should have the properties file in the classpath and use a servlet