<fmt:message> Tag
The <fmt:message> tag maps a key to a localized message, and then performs parameter substitution.
Syntax Format
<fmt:message key="<string>" bundle="<string>" var="<string>" scope="<string>"/>
Attributes
The <fmt:message> tag has the following attributes:
| Attribute | Description | Required | Default Value |
|---|---|---|---|
| key | The message key to retrieve | no | Body |
| bundle | The resource bundle to use | no | Default resource bundle |
| var | Variable name to store the localized message | no | Print to page |
| scope | Scope of the var attribute | 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:message 标签</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