<fmt:message> 標籤
<fmt:message>標籤映射一個關鍵字給局部消息,然後執行參數替換。
語法格式
<fmt:message key="<string>" bundle="<string>" var="<string>" scope="<string>"/>
屬性
<fmt:message>標籤有如下屬性:
| 屬性 | 描述 | 是否必要 | 默認值 |
|---|---|---|---|
| key | 要檢索的消息關鍵字 | 否 | Body |
| bundle | 要使用的資源束 | 否 | 默認資源束 |
| var | 存儲局部消息的變數名 | 否 | Print to page |
| scope | var屬性的作用域 | 否 | Page |
實例演示
<%@ 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.zaixian.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>
運行結果如下:
One Two Three

JSP 標準標籤庫