• 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:setBundle Tag

February 22, 2014 //  by Krishna Srinivasan//  Leave a Comment

The <fmt:setBundle> tag is used to creates a ResourceBundle and stores the ResourceBundle object into the given variable and scope.

The Syntax Of <fmt:setBundle> Tag

<fmt: setBundle basename= “ResourceBundle Name” var = “var name”/>

Attributes Of <fmt:setBundle> Tag

Attributes Description
basename Specifies the resource bundle name with the package name.
var Specifies the variable name to store new ResourceBundle.
scope The Scope into which the variable has to be set.

Example

Listing 1: SetBundleExample.java

package javabeat.net;

import java.util.ListResourceBundle;

public class SetBundleExample extends ListResourceBundle {
	public Object[ ][ ] getContents()
	{
		return contents;
	}
	static final Object[ ][ ] contents =
	  {
	  		{&quot;girls.sangeeta&quot;, &quot;sangeeta&quot;},
	  		{&quot;girls.mitali&quot;, &quot;mitali&quot;},
	  		{&quot;girls.nisha&quot;, &quot;nisha&quot;},
	  };
}

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

Listing 1: example.jsp

<%@ 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>setBundle Example</title>
</head>
<body>

	<fmt:setLocale value="ex" />
	<fmt:setBundle basename="javabeat.net.SetBundleExample" var="lang" />
	<fmt:message key="girls.sangeeta" bundle="${lang}" />
	<br />
	<fmt:message key="girls.mitali" bundle="${lang}" />
	<br />
	<fmt:message key="girls.nisha" 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:setLocale value= “ex”/> sets the locale in the jsp file of the ResourceBundle Class.
  • In setBundle basename we have declared the package name (javabeat.net) and resource bundle name (SetBundleExample).
  • var is used for specifying the variable name.
  • 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 :
JSTL_fmt setBundle tag_demo

Previous Tutorial : JSTL Format fmt:setLocale Tag :: Next Tutorial : JSTL Format fmt:formatNumber 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: « JSTL Format fmt:setLocale Tag
Next Post: EclipseLink / JPA – com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column »

Reader Interactions

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.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

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