fmt:bundle tag
fmt:bundleThe tag makes the specified resource bundle available to thefmt:bundletags appearing in thefmt:messagetag. This can save you many steps of specifying the resource bundle for everyfmt:messagetag.
For example, the following twofmt:bundleblocks will produce the same output:
Syntax format
property
fmt:bundleThe tag has the following attributes:
| property | Description | Whether it is required | Default value |
|---|---|---|---|
| basename | Specifies the base name of the resource bundle to be loaded | Is | None |
| prefix | specifiedfmt:messageThe prefix for the key attribute of the tag | No | None |
Program Example
A resource bundle contains locale-specific objects. A resource bundle contains key-value pairs. When your program needs locale-specific resources, you can share all the keys across all locales, but you can also specify translated values for a locale. Resource bundles help provide content specific to a locale.
A Java resource bundle file contains a series of key-value pairs. The approach we are concerned with involves creating compiled Java classes that inherit from the java.util.ListResourceBundle class. You must compile these classes and place them in the CLASSPATH of your web application.
Let's define a default resource bundle:
package com.runoob;
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 into Example.class, then place it where the web application's CLASSPATH can find it. Now you can 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" %>
JSTL fmt:bundle 标签
The running result is as follows:
One
Two
Three
Change it to have no prefix attribute:
<%@ 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" %>
JSTL fmt:bundle 标签
The running result is as follows:
One
Two
Three
You can checkfmt:setLocaleandfmt:setBundlefor more information.
JSP Standard Tag Library