JSTL fmt Tag param Example

JSTL fmt Tag param Example


Posted in : Java Posted on : April 6, 2012 at 7:38 PM Comments : [ 0 ]

In this tutorial you will learn about the JSTL fmt tag tag in JSP.

JSTL fmt Tag param Example

In this tutorial you will learn about the JSTL fmt tag <fmt:param> tag in JSP.

In JSTL fmt, param tag is used to give the value as a parameter for the text message.

Atributes of <fmt:param>

  • value : This is an optional attribute used for providing the value as a parameter to the tag which contains it. i.e the <message> tag.

Example :

Here an example is being given which will demonstrate you the purpose of using <fmt:param> tag. In this example I have used this tag with the <fmt:message> tag to provide the argument. At first I have created a properties file for the German Locale named Pop_de.properties. Then created a JSP page to handle the properties file. For this on the JSP page I have set the German Locale using the <fmt:setLocale> tag then uses the <fmt:bundle> tag to load the bundle resource and then to display the values of properties file used the <fmt:message> tag with key and var attribute and also used the <fmt:param> tag to provide the argument to the <fmt:message> tag, here the value of <fmt:param> tag will be passed as parameter and will display with the value mapped with the corresponding specified key.

Pop_de.properties

Name=willkommen {0}
Address=ich
Number=996677554

JstlFmtParam.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fmt:message Tag</title>
</head>
<body>
<p>German Locale</p>
<fmt:setLocale value="de"/>
<fmt:bundle basename="myProperties.Prop.Pop">
<fmt:message key="Name" var="r" >
<fmt:param value="Bipul"/>
</fmt:message>
</fmt:bundle>
<h2><c:out value="${r}"/></h2>
</body>
</html>

How to run this example

Here I am using an IDE Eclipse so I am giving the process of executing this example in perspective of Eclipse. Before executing this example you will have needed to add the following jar files :

  • jstl.jar
  • standard.jar

After adding of these jar files you may execute your program in the following ways :

  • Select JstlFmtParam.jsp file of your project in Project Explorer -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • On the Eclipse Editor go to your JstlFmtParam.jsp -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • Go to Run button look at the toolbar in green color and click -> Choose your server -> Finish.
  • A simplest way to execute the example in Eclipse is to use the CTRL+F11 key -> Run On Server -> Choose your server -> Finish

NOTE : In all of the above execution processes you may start the server first and stop the server each time after the execution if not, each time you will may prompted to a dialog box to Restart the server in Eclipse.

Output :

When the execution process will be completed successfully an output will be displayed on your eclipse browser as :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics