Solved

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

Posted on 2007-11-26
3
9,720 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 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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