• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10320
  • Last Modified:

How to use JSTL/JSP to read a Java property file, NOT Internationalization or localization related.

In a JSP web application deployed to Tomcat 5.5 on XP, I have a property file, its content is something like (name/value pair, note the value is comma separated file names) ...


In the JSP page, I would like to use JSTL to read the property file, parse the value by comma, then output the file name one by one.

Where do I need to put the property file?
1 Solution
You need to place the file on the classpath. e.g. ../MyApp/WEB-INF/classes/myfile.properties

To load the properties file in jsp, use <fmt:..> to load the bundle and store the message value to variable.
    <fmt:setBundle var="mybundle" basename="myfile"/>
    <fmt:message var="names" key="fileName" bundle="${mybundle}"/>

Then use <c:forTokens> to split and loop the list. e.g.
    <c:forTokens var="file" items="${names}" delims=",">
        <c:out value="${file}"/>

llinesriAuthor Commented:
Great tip. It works as you suggested.
How to load the property file which is not in classpath. I deployed the war file into Jboss, also added the property file into same folder. How to read that property file in the jsp page ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now