JSP中常用的JSTL fmt(format格式化)標(biāo)簽用法整理
JSTL標(biāo)簽提供了對國際化(I18N)的支持,它可以根據(jù)發(fā)出請求的客戶端地域的不同來顯示不同的語言。同時還提供了格式化數(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個標(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)簽
用來將字符串類型的時間或日期轉(zhuǎn)換成日期時間類型
<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)時區(qū)或?qū)r區(qū)存儲到屬性范圍中
<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ù)來源,也可以將其存儲到一定范圍中,供需要時使用
<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ù)(在從資源文件中取得信息時,可能需要動態(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)文章
JavaBean實(shí)現(xiàn)多文件上傳的兩種方法
JavaBean實(shí)現(xiàn)多文件上傳的兩種方法...2006-10-10JSP實(shí)現(xiàn)百萬富翁猜數(shù)字游戲
這篇文章主要為大家詳細(xì)介紹了JSP實(shí)現(xiàn)百萬富翁猜數(shù)字游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06JSP XMLHttpRequest動態(tài)無刷新及其中文亂碼處理
最近用到了XMLHttpRequest 動態(tài)無刷新技術(shù) 不刷新當(dāng)前頁面發(fā)送請求,并得到返回結(jié)果 主要是jsp頁面內(nèi)的js與后臺的servlet交互,返回值為文本~~~2009-07-07jsp登陸校驗演示 servlet、login、success
這篇文章主要為大家詳細(xì)介紹了jsp登陸校驗演示,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12