Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a .properties file into a jsp

Tags:

java

jsp

servlets

I've gotten as far as this:

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

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?

like image 410
morgancodes Avatar asked Jul 16 '09 22:07

morgancodes


1 Answers

This will do the job:

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

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

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

like image 114
victor hugo Avatar answered Sep 19 '22 15:09

victor hugo