JSP中常用的JSTL fmt(format格式化)標(biāo)簽用法整理
JSTL標(biāo)簽提供了對(duì)國際化(I18N)的支持,它可以根據(jù)發(fā)出請(qǐng)求的客戶端地域的不同來顯示不同的語言。同時(shí)還提供了格式化數(shù)據(jù)和日期的方法。實(shí)現(xiàn)這些功能需要I18N格式標(biāo)簽庫(I18N-capable formation tags liberary)。引入該標(biāo)簽庫的方法為:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
I18N格式標(biāo)簽庫提供了11個(gè)標(biāo)簽,這些 標(biāo)簽從功能上可以劃分為3類如下:
(1)數(shù)字日期格式化。formatNumber標(biāo)簽、formatData標(biāo)簽、parseNumber標(biāo)簽、parseDate標(biāo)簽、timeZone標(biāo)簽、setTimeZone標(biāo)簽。
(2)讀取消息資源。bundle標(biāo)簽、message標(biāo)簽、setBundle標(biāo)簽。
(3)國際化。setlocale標(biāo)簽、requestEncoding標(biāo)簽。
接下將詳細(xì)介紹這些標(biāo)簽的功能和使用方式。
<fmt:formatNumber>標(biāo)簽
根據(jù)區(qū)域或定制的方式將數(shù)字格式化成數(shù)字、貨幣或百分比
<fmt:formatNumber value="number" [type={number|currency|percent|}]
[pattern="pattern"]
[currencyCode="currencyCode"]
[currentSymbol="currentSymbol"]
[groupingUsec="{true|false}"]
[maxIntergerDigits="maxIntergerDigits"]
[minIntergerDigits="minIntergerDigits"]
[maxFractionDigits="maxFractionDigits"]
[minFractionDigits="minFractionDigits"]
[var="varname"]
[scope="page|request|session|application"]
/>
<%@page language="java" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>FormatNumber標(biāo)簽使用</title>
</head>
<body>
<h1>FormatNumber標(biāo)簽使用</h1>
<fmt:setLocale value="fr_fr" />
France:<fmt:formatNumber value="123456789.012"/>
<fmt:setLocale value="zh_cn" />
China:<fmt:formatNumber value="123456789.012"/>
<fmt:setLocale value="de_de" />
Germany:<fmt:formatNumber value="123456789.012"/>
</body>
</html>
<fmt:parseNumber />標(biāo)簽
用來將字符串類型的數(shù)字、貨幣、或百分比轉(zhuǎn)換成數(shù)字類型
<fmt:parseNumber value="numberString" [type={number|currency|percent|}]
[pattern="pattern"]
[parseLocale="parseLocale"]
[integerOnly="{false|true}"]
[var="varname"]
[scope="page|request|session|application"]
/>
<fmt:formatDate />標(biāo)簽
用來將日期類型轉(zhuǎn)換為字符串類型日期
<fmt:formatDate value="number" [type={time|date|both}]
[pattern="pattern"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[timeZone="timeZone"]
[var="varname"]
[scope="page|request|session|application"]
/>
<fmt:parseDate />標(biāo)簽
用來將字符串類型的時(shí)間或日期轉(zhuǎn)換成日期時(shí)間類型
<fmt:parseDate value="date" [type={time|date|both}]
[pattern="pattern"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[timeZone="timeZone"]
[var="varname"]
[scope="page|request|session|application"]
/>
<fmt:setTimeZone />標(biāo)簽
用來設(shè)置默認(rèn)時(shí)區(qū)或?qū)r(shí)區(qū)存儲(chǔ)到屬性范圍中
<fmt:setTimeZone value="timezone" [var="varname"] [scope="{page|request|session|application}"] />
<fmt:timeZone value="timeZone"> 本體內(nèi)容 </fmt:timeZone>
<fmt:setLocale />標(biāo)簽
用來設(shè)定用戶的區(qū)域語言
<fmt:setLocale value="locale" [variant="variant"] [scope="{page|request|session|application}"] />
<fmt:requestEncoding value="charsetName" />
<fmt:setBundle />標(biāo)簽
用來設(shè)定默認(rèn)的數(shù)據(jù)來源,也可以將其存儲(chǔ)到一定范圍中,供需要時(shí)使用
<fmt:setBundle basename="basename" [var="varname"] [scope="{page|request|session|application}"] />
<fmt:message />標(biāo)簽
用來從指定的資源文件中通過索引取得值
<fmt:message key="messageKey" [bundle="resourceBundle"] [var="varname"] [scope="{page|request|session|application}"] />
<fmt:param />標(biāo)簽
用來傳遞參數(shù)(在從資源文件中取得信息時(shí),可能需要?jiǎng)討B(tài)設(shè)定參數(shù)的情況下)
<fmt:param value="messageParameter" />
沒有本體內(nèi)容
<fmt:param value="messageParameter" >有本體內(nèi)容 參數(shù) </fmt:param>
<fmt:bundle />標(biāo)簽
用來設(shè)定數(shù)據(jù)來源
<fmt:bundle basename="basename" [prefix="prefix"] > 本體內(nèi)容<fmt:message> </fmt:bundle>
相關(guān)文章
JSP實(shí)現(xiàn)計(jì)算器功能(網(wǎng)頁版)
這篇文章講述了JSP實(shí)現(xiàn)計(jì)算器功能的詳細(xì)代碼,網(wǎng)頁版的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-12-12

