如何将.properties文件加载到jsp中 [英] How to load a .properties file into a 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
这篇关于如何将.properties文件加载到jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文