• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JSTL Format fmt:message Tag

February 27, 2014 //  by Krishna Srinivasan

The <fmt: message> tag maps key to localized message to return the value using the resource bundle specified in the bundle attribute.

Syntax Of <fmt: message> Tag

<fmt: message attributes> body content </fmt: message>

Attributes Of <fmt: message> Tag

Attributes Description
key It is used for specifying the key whose value which we want to display.
bundle Specifies the resource bundle that is used to get the value of the specified key.
var Specifies the variable name to store the retrieved message .
scope The Scope into which the variable has to be set.

Example

Listing 1:Message .java

package javabeat.net;

import java.util.ListResourceBundle;

public class Message extends ListResourceBundle
{
	public Object[ ][ ] getContents()
	{
		return contents;
	}
	static final Object[ ][ ] contents =
	  {
	  		{"color.blue", "blue"},
	  		{"color.pink", "pink"},
	  		{"color.yellow", "yellow"},
	  };
}

Details of the Code
ListResourceBundle is used to manage the list of values. The class Message extends the ListResourceBundle to get list of values by using getContent method.

Listing 2:example.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<html>
<head>

<title>Message tag</title>
</head>
<body>

<fmt:setBundle basename="javabeat.net.Message" var="lang"/>

<fmt:message key="color.blue" bundle="${lang}"/><br/>
   <fmt:message key="color.pink" bundle="${lang}"/><br/>
  <fmt:message key="color.yellow" bundle="${lang}"/><br/>

</body>
</html>

Details of the Code

  • <%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %> tag is used for formatting the data in jsp page.
  • <fmt: message> tag with key attribute is used to display the specified message.
  • bundle is used to get the value of specified key

Steps for Execution

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process is completed successfully we will get the following output :
fmt message tag output

 

Previous Tutorial : JSTL Format fmt:setTimeZone Tag :: Next Tutorial : JSTL Format fmt:requestEncoding Tag

Category: Java EETag: JSTL Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « PrimeFaces 5.0 Released
Next Post: JSTL Format fmt:requestEncoding Tag »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Implement getActiveCount() Method of ThreadPoolExeceutor in Java

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact