This tutorial explains how to find dropdown values from properties file in JSP. This example is created in eclipse IDE and run on tomcat server.
Dropdown Values From Properties File
This tutorial explains how to find dropdown values from properties file in JSP. This example is created in eclipse IDE and run on tomcat server. The application directory structure will look like as below, if you are using an Eclipse editor for developing the application.
This tutorial applies following steps.
Step 1 :
First we create Dynamic web project "dropdown-values-from-propertiesfile" in eclipse IDE . Now we create "index.jsp" file under WebContent folder. The code of "index.jsp" are given as:
<%@ page language="java" import="java.util.*" %>< h1 align="center" > Dropdown Values From Properties File </h1><% ResourceBundle messages =ResourceBundle.getBundle( "messages");Enumeration messageKeys = messages.getKeys(); %> <table align="center" > <tr> <td> Select User:</td> <td> <select name="user" > <% while(messageKeys.hasMoreElements()){String key = (String)messageKeys.nextElement(); String value = messages.getString(key); %> <option value="<%=messages.getString(key)%>"> <%=messages.getString(key)%> </option> <%} %> </select> </td> </tr> </table> |
Step 2 :
Now we create "messages.properties" file under src and this file used as properties file. The code of "messages.properties" file given below as :
# messages properties user1.name= Rameshuser2.name= Sureshuser3.name= Dineshuser4.name= Mahesh |
Step 3 :
Now we can open "web.xml" file and modify as:
<? xml version="1.0" encoding="UTF-8"?>< web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Dropdown Values From Properties Files</display-name> <welcome-file-list> <welcome-file>index.htm</welcome-file> </welcome-file-list></ web-app> |
Step 4 :
When run this application on tomcat server displays output as:
In this dropdown values are find from properties file "messages.properties" .
Download Code
[ 0 ] Comments