Solved

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

Posted on 2007-11-26
3
9,966 Views
Last Modified: 2010-04-21
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) ...

fileName=file1,file2,file3,file4

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?
0
Comment
Question by:llinesri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
boonleng earned 500 total points
ID: 20355351
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}"/>
    </c:forTokens>

0
 

Author Closing Comment

by:llinesri
ID: 31411120
Great tip. It works as you suggested.
0
 
LVL 1

Expert Comment

by:mallesh_np
ID: 22345282
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 ?
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question