Latest web development tutorials

<Fmt: bundle> tag

JSP Standard Tag Library JSP Standard Tag Library

<Fmt: bundle> tag specified resource bundle to appear in the <fmt: bundle> tag in the <fmt: message> tag is available. This allows you to save for each <fmt: message> tag specifies the number of steps resource bundles.

For example, the following two <fmt: bundle> block will produce the same output:

<fmt:bundle basename="com.tutorialspoint.Example">
    <fmt:message key="count.one"/>
</fmt:bundle>

<fmt:bundle basename="com.tutorialspoint.Example" prefix="count.">
    <fmt:message key="title"/>
</fmt:bundle>

Syntax

<fmt:bundle baseName="<string>" prefix="<string>"/>

Attributes

<Fmt: bundle> tag has the following attributes:

Attributes description If necessary Defaults
basename Specify the base name of the resource bundle is loaded Yes no
prefix Specifies the <fmt: message> tag prefix key attributes no no


Program Example

Resource bundles contain locale-specific objects. Resource bundles contain key-value pairs. When your program needs to region-specific resources, we can all share the locale for all keywords, but you can also specify the converted value for the locale. It can help provide resource bundle locale assigned to the content.

A Java resource bundle file contains a list of key-value pairs. The method we are concerned involves creating a class inherits from java.util.ListResourceBundle compiled Java classes. You must compile these classes and then placed in CLASSPATH your Web application program.

Let's define a default resource bundle:

package com.w3big;

import java.util.ListResourceBundle;

public class Example_En extends ListResourceBundle {
  public Object[][] getContents() {
    return contents;
  }
  static final Object[][] contents = {
  {"count.one", "One"},
  {"count.two", "Two"},
  {"count.three", "Three"},
  };
}

Compile the above file Examble.class, then placed CLASSPATH Web application can find them. You can now use JSTL to display these three numbers, like this:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>JSTL fmt:bundle 标签</title>
</head>
<body>

<fmt:bundle basename="com.w3big.Example" prefix="count.">
   <fmt:message key="one"/><br/>
   <fmt:message key="two"/><br/>
   <fmt:message key="three"/><br/>
</fmt:bundle>

</body>
</html>

Results are as follows:

One 
Two 
Three

No prefix to its properties:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>JSTL fmt:bundle 标签</title>
</head>
<body>

<fmt:bundle basename="com.w3big.Example">
   <fmt:message key="count.one"/><br/>
   <fmt:message key="count.two"/><br/>
   <fmt:message key="count.three"/><br/>
</fmt:bundle>

</body>
</html>

Results are as follows:

One 
Two 
Three

You can view the <fmt: setLocale> and <fmt: setBundle> for more information.


JSP Standard Tag Library JSP Standard Tag Library