Dropdown Values From Properties File


Posted in : Servlet Posted on : April 28, 2011 at 5:47 PM Comments : [ 0 ]
Advertisements
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.

1122dropdown-values-fpf1.gif

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=Ramesh

user2.name=Suresh

user3.name=Dinesh

user4.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:

1122dropdown-values-fpf2.gif

In this dropdown values are find from properties file "messages.properties" .

Download Code

Download example code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Tutorial Topics