<fmt:setBundle> Tag
The <fmt:setBundle> tag is used to load a resource bundle and store it in a named variable in scope or a bundle configuration variable.
Syntax Format
<fmt:setBundle baseName="<string>" var="<string>" scope="<string>"/>
Attributes
The <fmt:setBundle> tag has the following attributes:
| Attribute | Description | Required | Default Value |
|---|---|---|---|
| basename | Base name of the resource bundle family, exposed to a scoped variable or configuration variable | Yes | None |
| var | Variable to store the new resource bundle | no | Replace default |
| scope | Scope of the variable | no | Page |
Example Demonstration
<%@ 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:setBundle 标签</title>
</head>
<body>
<fmt:setLocale value="en"/>
<fmt:setBundle basename="com.example.Example" var="lang"/>
<fmt:message key="count.one" bundle="${lang}"/><br/>
<fmt:message key="count.two" bundle="${lang}"/><br/>
<fmt:message key="count.three" bundle="${lang}"/><br/>
</body>
</html>
The output is as follows:
One Two Three
Other Extensions
JSP Standard Tag Library