Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-26
3
Medium Priority
?
10,164 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
3 Comments
 
LVL 14

Accepted Solution

by:
boonleng earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 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