目錄
- fmt:formatNumber標籤
- fmt:parseNumber 標籤
- fmt:formatDate 標籤
- fmt:parseDate 標籤
- fmt:bundle 標籤
- fmt:setLocale 標籤
- fmt:setBundle 標籤
- fmt:timeZone 標籤
- fmt:message 標籤
- fmt:requestEncoding 標籤
fmt:formatNumber標籤
<fmt:formatNumber>標籤用於格式化數字,百分比,貨幣。
語法格式
<fmt:formatNumber
value="<string>"
type="<string>"
pattern="<string>"
currencyCode="<string>"
currencySymbol="<string>"
groupingUsed="<string>"
maxIntegerDigits="<string>"
minIntegerDigits="<string>"
maxFractionDigits="<string>"
minFractionDigits="<string>"
var="<string>"
scope="<string>"/>
屬性
<fmt:formatNumber>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 要顯示的數字 | 是 | 無 |
type | NUMBER,CURRENCY,或 PERCENT類型 | 否 | Number |
pattern | 指定一個自定義的格式化模式用與輸出 | 否 | 無 |
currencyCode | 貨幣碼(當type="currency"時) | 否 | 取決於默認區域 |
currencySymbol | 貨幣符號 (當 type="currency"時) | 否 | 取決於默認區域 |
groupingUsed | 是否對數字分組 (TRUE 或 FALSE) | 否 | true |
maxIntegerDigits | 整型數最大的位數 | 否 | 無 |
minIntegerDigits | 整型數最小的位數 | 否 | 無 |
maxFractionDigits | 小數點後最大的位數 | 否 | 無 |
minFractionDigits | 小數點後最小的位數 | 否 | 無 |
var | 存儲格式化數字的變量 | 否 | Print to page |
scope | var屬性的作用域 | 否 | page |
如果type屬性爲percent或number,那麼您就可以使用其它幾個格式化數字屬性。maxIntegerDigits屬性和minIntegerDigits屬性允許您指定整數的長度。若實際數字超過了maxIntegerDigits所指定的最大值,則數字將會被截斷。
有一些屬性允許您指定小數點後的位數。minFractionalDigits屬性和maxFractionalDigits屬性允許您指定小數點後的位數。若實際的數字超出了所指定的範圍,則這個數字會被截斷。
數字分組可以用來在每三個數字中插入一個逗號。groupingIsUsed屬性用來指定是否使用數字分組。當與minIntegerDigits屬性一同使用時,就必須要很小心地來獲取預期的結果了。
您或許會使用pattern屬性。這個屬性可以讓您在對數字編碼時包含指定的字符。接下來的表格中列出了這些字符。
符號 | 描述 |
---|---|
0 | 代表一位數字 |
E | 使用指數格式 |
# | 代表一位數字,若沒有則顯示 0,前導 0 和追尾 0 不顯示。 |
. | 小數點 |
, | 數字分組分隔符 |
; | 分隔格式 |
- | 使用默認負數前綴 |
% | 百分數 |
? | 千分數 |
¤ | 貨幣符號,使用實際的貨幣符號代替 |
X | 指定可以作爲前綴或後綴的字符 |
' | 在前綴或後綴中引用特殊字符 |
實例演示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>JSTL fmt:formatNumber 標籤</title>
</head>
<body>
<h3>數字格式化:</h3>
<c:set var="balance" value="120000.2309" />
<p>格式化數字 (1): <fmt:formatNumber value="${balance}"
type="currency"/></p>
<p>格式化數字 (2): <fmt:formatNumber type="number"
maxIntegerDigits="3" value="${balance}" /></p>
<p>格式化數字 (3): <fmt:formatNumber type="number"
maxFractionDigits="3" value="${balance}" /></p>
<p>格式化數字 (4): <fmt:formatNumber type="number"
groupingUsed="false" value="${balance}" /></p>
<p>格式化數字 (5): <fmt:formatNumber type="percent"
maxIntegerDigits="3" value="${balance}" /></p>
<p>格式化數字 (6): <fmt:formatNumber type="percent"
minFractionDigits="10" value="${balance}" /></p>
<p>格式化數字 (7): <fmt:formatNumber type="percent"
maxIntegerDigits="3" value="${balance}" /></p>
<p>格式化數字 (8): <fmt:formatNumber type="number"
pattern="###.###E0" value="${balance}" /></p>
<p>美元 :
<fmt:setLocale value="en_US"/>
<fmt:formatNumber value="${balance}" type="currency"/></p>
</body>
</html>
運行結果如下:
數字格式化:
格式化數字 (1): ¥120,000.23
格式化數字 (2): 000.231
格式化數字 (3): 120,000.231
格式化數字 (4): 120000.231
格式化數字 (5): 023%
格式化數字 (6): 12,000,023.0900000000%
格式化數字 (7): 023%
格式化數字 (8): 120E3
美元 : $120,000.23
fmt:parseNumber 標籤
<fmt:parseNumber>標籤用來解析數字,百分數,貨幣。
語法格式
<fmt:parseNumber
value="<string>"
type="<string>"
pattern="<string>"
parseLocale="<string>"
integerOnly="<string>"
var="<string>"
scope="<string>"/>
屬性
<fmt:parseNumber>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 要解析的數字 | 否 | Body |
type | NUMBER,,CURRENCY,或 PERCENT | 否 | number |
parseLocale | 解析數字時所用的區域 | 否 | 默認區域 |
integerOnly | 是否只解析整型數(true)或浮點數(false) | 否 | false |
pattern | 自定義解析模式 | 否 | 無 |
timeZone | 要顯示的日期的時區 | 否 | 默認時區 |
var | 存儲待解析數字的變量 | 否 | Print to page |
scope | var屬性的作用域 | 否 | page |
pattern屬性與<fmt:formatNumber>標籤中的pattern有相同的作用。在解析時,pattern屬性告訴解析器期望的格式。
實例演示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>JSTL fmt:parseNumber 標籤</title>
</head>
<body>
<h3>數字解析:</h3>
<c:set var="balance" value="1250003.350" />
<fmt:parseNumber var="i" type="number" value="${balance}" />
<p>數字解析 (1) : <c:out value="${i}" /></p>
<fmt:parseNumber var="i" integerOnly="true"
type="number" value="${balance}" />
<p>數字解析 (2) : <c:out value="${i}" /></p>
</body>
</html>
運行結果如下:
數字解析:
數字解析 (1) : 1250003.35
數字解析 (2) : 1250003
fmt:formatDate 標籤
<fmt:formatDate>標籤用於使用不同的方式格式化日期。
語法格式
<fmt:formatDate
value="<string>"
type="<string>"
dateStyle="<string>"
timeStyle="<string>"
pattern="<string>"
timeZone="<string>"
var="<string>"
scope="<string>"/>
屬性
<fmt:formatDate>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 要顯示的日期 | 是 | 無 |
type | DATE, TIME, 或 BOTH | 否 | date |
dateStyle | FULL, LONG, MEDIUM, SHORT, 或 DEFAULT | 否 | default |
timeStyle | FULL, LONG, MEDIUM, SHORT, 或 DEFAULT | 否 | default |
pattern | 自定義格式模式 | 否 | 無 |
timeZone | 顯示日期的時區 | 否 | 默認時區 |
var | 存儲格式化日期的變量名 | 否 | 顯示在頁面 |
scope | 存儲格式化日誌變量的範圍 | 否 | 頁面 |
<fmt:formatDate> 標籤格式模式
代碼 | 描述 | 實例 |
---|---|---|
G |
時代標誌 |
AD |
y |
不包含紀元的年份。如果不包含紀元的年份小於 10,則顯示不具有前導零的年份。 |
2002 |
M |
月份數字。一位數的月份沒有前導零。 |
April & 04 |
d |
月中的某一天。一位數的日期沒有前導零。 |
20 |
h |
12 小時制的小時。一位數的小時數沒有前導零。 |
12 |
H |
24 小時制的小時。一位數的小時數沒有前導零。 |
0 |
m |
分鐘。一位數的分鐘數沒有前導零。 |
45 |
s |
秒。一位數的秒數沒有前導零。 |
52 |
S |
毫秒 |
970 |
E |
周幾 |
Tuesday |
D |
一年中的第幾天 |
180 |
F |
一個月中的第幾個周幾 |
2 (一個月中的第二個星期三) |
w |
一年中的第幾周r |
27 |
W |
一個月中的第幾周 |
2 |
a |
a.m./p.m. 指示符 |
PM |
k |
小時(12 小時制的小時) |
24 |
K |
小時(24 小時制的小時) |
0 |
z |
時區 |
中部標準時間 |
' |
轉義文本 |
|
'' |
單引號 |
實例演示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>JSTL fmt:dateNumber 標籤</title>
</head>
<body>
<h3>日期格式化:</h3>
<c:set var="now" value="<%=new java.util.Date()%>" />
<p>日期格式化 (1): <fmt:formatDate type="time"
value="${now}" /></p>
<p>日期格式化 (2): <fmt:formatDate type="date"
value="${now}" /></p>
<p>日期格式化 (3): <fmt:formatDate type="both"
value="${now}" /></p>
<p>日期格式化 (4): <fmt:formatDate type="both"
dateStyle="short" timeStyle="short"
value="${now}" /></p>
<p>日期格式化 (5): <fmt:formatDate type="both"
dateStyle="medium" timeStyle="medium"
value="${now}" /></p>
<p>日期格式化 (6): <fmt:formatDate type="both"
dateStyle="long" timeStyle="long"
value="${now}" /></p>
<p>日期格式化 (7): <fmt:formatDate pattern="yyyy-MM-dd"
value="${now}" /></p>
</body>
</html>
以上實例運行結果:
日期格式化:
日期格式化 (1): 11:19:43
日期格式化 (2): 2016-6-26
日期格式化 (3): 2016-6-26 11:19:43
日期格式化 (4): 16-6-26 上午11:19
日期格式化 (5): 2016-6-26 11:19:43
日期格式化 (6): 2016年6月26日 上午11時19分43秒
日期格式化 (7): 2016-06-26
fmt:parseDate 標籤
<fmt:parseDate> 標籤用於解析日期。
語法格式
<fmt:parseDate
value="<string>"
type="<string>"
dateStyle="<string>"
timeStyle="<string>"
pattern="<string>"
timeZone="<string>"
parseLocale="<string>"
var="<string>"
scope="<string>"/>
屬性
<fmt:parseDate>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 要顯示的日期 | 是 | 無 |
type | DATE, TIME, 或 BOTH | 否 | date |
dateStyle | FULL, LONG, MEDIUM, SHORT, 或 DEFAULT | 否 | default |
timeStyle | FULL, LONG, MEDIUM, SHORT, 或 DEFAULT | 否 | default |
pattern | 自定義格式模式 | 否 | 無 |
timeZone | 顯示日期的時區 | 否 | 默認時區 |
var | 存儲格式化日期的變量名 | 否 | 顯示在頁面 |
scope | 存儲格式化日誌變量的範圍 | 否 | 頁面 |
屬性設置我們需要的輸出的時間格式。
實例演示
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>JSTL fmt:parseDate 標籤</title>
</head>
<body>
<h3>日期解析:</h3>
<c:set var="now" value="20-10-2015" />
<fmt:parseDate value="${now}" var="parsedEmpDate"
pattern="dd-MM-yyyy" />
<p>解析後的日期爲: <c:out value="${parsedEmpDate}" /></p>
</body>
</html>
以上實例運行結果:
日期解析:
解析後的日期爲: Tue Oct 20 00:00:00 CST 2015
fmt:bundle 標籤
<fmt:bundle>標籤將指定的資源束對出現在<fmt:bundle>標籤中的<fmt:message>標籤可用。這可以使您省去爲每個<fmt:message>標籤指定資源束的很多步驟。
舉例來說,下面的兩個<fmt:bundle>塊將產生同樣的輸出:
<fmt:bundle basename="com.tutorialspoint.Example">
<fmt:message key="count.one"/>
</fmt:bundle>
<fmt:bundle basename="com.tutorialspoint.Example" prefix="count.">
<fmt:message key="title"/>
</fmt:bundle>
語法格式
<fmt:bundle baseName="<string>" prefix="<string>"/>
屬性
<fmt:bundle>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
basename | 指定被載入的資源束的基礎名稱 | 是 | 無 |
prefix | 指定<fmt:message>標籤key屬性的前綴 | 否 | 無 |
程序示例
資源束包含區域特定對象。資源束包含鍵值對。當您的程序需要區域特定資源時,可以將所有的關鍵詞對所有的locale共享,但是也可以爲locale指定轉換後的值。資源束可以幫助提供指定給locale的內容。
一個Java資源束文件包含一系列的鍵值對。我們所關注的方法涉及到創建繼承自java.util.ListResourceBundle 類的已編譯Java類。您必須編譯這些類然後放在您的Web應用程序的CLASSPATH中。
讓我們來定義一個默認的資源束:
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"},
};
}
編譯以上文件爲Examble.class,然後放在Web應用程序的CLASSPATH能找到的地方。現在可以使用JSTL來顯示這三個數字了,就像這樣:
<%@ 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:bundle 標籤</title>
</head>
<body>
<fmt:bundle basename="com.runoob.Example" prefix="count.">
<fmt:message key="one"/><br/>
<fmt:message key="two"/><br/>
<fmt:message key="three"/><br/>
</fmt:bundle>
</body>
</html>
運行結果如下:
One
Two
Three
將其改爲無prefix屬性:
<%@ 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:bundle 標籤</title>
</head>
<body>
<fmt:bundle basename="com.runoob.Example">
<fmt:message key="count.one"/><br/>
<fmt:message key="count.two"/><br/>
<fmt:message key="count.three"/><br/>
</fmt:bundle>
</body>
</html>
運行結果如下:
One
Two
Three
fmt:setLocale 標籤
<fmt:setLocale>標籤用來將給定的區域存儲在locale配置變量中。
語法格式
<fmt:setLocale value="<string>" variant="<string>" scope="<string>"/>
屬性
<fmt:setLocale>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 指定ISO-639 語言碼和ISO-3166 國家碼 | 是 | en_US |
variant | 特定瀏覽器變體 | 否 | 無 |
scope | Locale配置變量的作用域 | 否 | Page |
程序示例
資源束包含區域特定對象。資源束包含鍵值對。當您的程序需要區域特定資源時,可以將所有的關鍵詞對所有的locale共享,但是也可以爲locale指定轉換後的值。資源束可以幫助提供指定給locale的內容。
一個Java資源束文件包含一系列的鍵值對。我們所關注的方法涉及到創建繼承自java.util.ListResourceBundle 類的已編譯Java類。您必須編譯這些類然後放在您的Web應用程序的CLASSPATH中。
讓我們來定義一個默認的資源束:
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"},
};
}
現在,再定義一個資源束,用於Spanish Locale:
package com.runoob;
import java.util.ListResourceBundle;
public class Example_es_ES extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{"count.one", "Uno"},
{"count.two", "Dos"},
{"count.three", "Tres"},
};
}
編譯以上文件至Examble.class和Examble_es_ES.class中,然後將它們放在Web應用程序的CLASSPATH中。現在可以使用JSTL標籤來顯示這三個數字,就像這樣:
<%@ 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:setLocale 標籤</title>
</head>
<body>
<fmt:bundle basename="com.runoob.Example">
<fmt:message key="count.one"/><br/>
<fmt:message key="count.two"/><br/>
<fmt:message key="count.three"/><br/>
</fmt:bundle>
<!-- 修改地區-->
<fmt:setLocale value="es_ES"/>
<fmt:bundle basename="com.runoob.Example">
<fmt:message key="count.one"/><br/>
<fmt:message key="count.two"/><br/>
<fmt:message key="count.three"/><br/>
</fmt:bundle>
</body>
</html>
運行結果如下:
One
Two
Three
Uno
Dos
Tres
fmt:setBundle 標籤
<fmt:setBundle>標籤用來載入一個資源束,然後將它存儲在作用域中已命名的變量或bundle配置變量中。
語法格式
<fmt:setBundle baseName="<string>" var="<string>" scope="<string>"/>
屬性
<fmt:setBundle>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
basename | 資源束家族基礎名稱,暴露給作用域變量或配置變量 | 是 | 無 |
var | 存儲新資源束的變量 | 否 | Replace default |
scope | 變量的作用域 | 否 | 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:setBundle 標籤</title>
</head>
<body>
<fmt:setLocale value="en"/>
<fmt:setBundle basename="com.runoob.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
fmt:timeZone 標籤
<fmt:timeZone>標籤用來指定時區,供其它標籤使用。
語法格式
<fmt:setLocale value="<string>" variant="<string>" scope="<string>"/>
屬性
<fmt:timeZone>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
value | 時區 | 是 | 無 |
實例演示
<%@ 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:timeZone 標籤</title>
</head>
<body>
<c:set var="now" value="<%=new java.util.Date()%>" />
<table border="1" width="100%">
<tr>
<td width="100%" colspan="2" bgcolor="#0000FF">
<p align="center">
<b>
<font color="#FFFFFF" size="4">Formatting:
<fmt:formatDate value="${now}" type="both"
timeStyle="long" dateStyle="long" />
</font>
</b>
</p>
</td>
</tr>
<c:forEach var="zone"
items="<%=java.util.TimeZone.getAvailableIDs()%>">
<tr>
<td width="51%">
<c:out value="${zone}" />
</td>
<td width="49%">
<fmt:timeZone value="${zone}">
<fmt:formatDate value="${now}" timeZone="${zn}"
type="both" />
</fmt:timeZone>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
運行結果如下:
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.runoob.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
fmt:requestEncoding 標籤
<fmt:requestEncoding>標籤用來指定返回給Web應用程序的表單編碼類型。
語法格式
<fmt:requestEncoding value="<string>"/>
屬性
<fmt:requestEncoding>標籤有如下屬性:
屬性 | 描述 | 是否必要 | 默認值 |
---|---|---|---|
key | 字符編碼集的名稱,用於解碼request參數 | 是 | 無 |
使用<fmt:requestEncoding>標籤來指定字符集,用於解碼來自表單的數據。在字符集不是ISO-8859-1時必須使用這個標籤。由於大多數瀏覽器在它們的請求中不包含Content-Type頭,所以需要這個標籤。
<fmt:requestEncoding>標籤的目的就是用來指定請求的Content-Type。您必須指定一個Content-Type,就算response是通過Page指令的contentType屬性來編碼。這是因爲response的實際區域可能與Page指令所指定的不同。
如果頁面包含 I18N-capable格式行爲用於設置response的locale屬性(通過調用ServletResponse.setLocale()方法),任何在頁面中指定的編碼集將會被覆蓋。
實例演示
<%@ 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:requestEncoding value="UTF-8" />
<fmt:setLocale value="es_ES"/>
<fmt:setBundle basename="com.runoob.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>
運行結果如下:
Uno
Dos
Tres