Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now