JavaBeat

  • Home
  • 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)
  • Privacy
  • Contact Us

JSTL Format fmt:bundle Tag

February 21, 2014 by Krishna Srinivasan Leave a Comment

The <fmt:bundle> tag is used to create a ResourceBundle object which will be used by its tag body.

Syntax Of <fmt:bundle> Tag

[code lang=”html”]
<fmt: bundle basename= “Resource Bundle Name” prefix= “msg”> body content </fmt: bundle>
[/code]

Attributes Of <fmt:bundle> Tag

  • basename – Specifies the resource bundle name with the package name.
  • prefix – Specifies prefix that has to be used for the message tag used in this element body content.

Example

Listing 1:Simplejstl

[code lang=”java”]
package javabeat.net;

import java.util.ListResourceBundle;

public class Simplejstl extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}

static final Object[][] contents = { { "color.red", "red" },
{ "color.blue", "blue" }, { "color.pink", "pink" }, };
}
[/code]

Details of the Code:

ListResourceBundle is abstract subclass of resource bundle. It is used to manage the list of values. The class Simplejstl extends the ListResourceBundle to get list of values by using getContent method.

Listing 2:example.jsp

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>fmt Bundle Tag</title>
</head>
<body>

<fmt:bundle basename="javabeat.net.Simplejstl" prefix="color.">
<fmt:message key="red"/><br/>
<fmt:message key="blue"/><br/>
<fmt:message key="pink"/><br/>

</fmt:bundle>

</body>
</html>
[/code]

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.
  • In base name we have declared the package name (javabeat.net) and resource bundle name (Simplejstl).
  • Prefix is used for the message tag used in element body content.

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 bundle tag output

Previous Tutorial : JSTL Format Tags :: Next Tutorial : JSTL Format fmt:formatDate Tag

Filed Under: Java EE Tagged With: 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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved