Latest web development tutorials

<fmt:message> 標籤

JSP 標準標籤庫 JSP標準標籤庫

<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.w3big.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 標準標籤庫 JSP標準標籤庫