jstl标签提供了对国际化(i18n)的支持,它可以根据发出请求的客户端地域的不同来显示不同的语言。同时还提供了格式化数据和日期的方法。实现这些功能需要i18n格式标签库(i18n-capable formation tags liberary)。引入该标签库的方法为:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
i18n格式标签库提供了11个标签,这些 标签从功能上可以划分为3类如下:
(1)数字日期格式化。formatnumber标签、formatdata标签、parsenumber标签、parsedate标签、timezone标签、settimezone标签。
(2)读取消息资源。bundle标签、message标签、setbundle标签。
(3)国际化。setlocale标签、requestencoding标签。
接下将详细介绍这些标签的功能和使用方式。
<fmt:formatnumber>标签
根据区域或定制的方式将数字格式化成数字、货币或百分比
<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标签使用</title>
</head>
<body>
<h1>formatnumber标签使用</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 />标签
用来将字符串类型的数字、货币、或百分比转换成数字类型
<fmt:parsenumber value="numberstring" [type={number|currency|percent|}]
[pattern="pattern"]
[parselocale="parselocale"]
[integeronly="{false|true}"]
[var="varname"]
[scope="page|request|session|application"]
/>
<fmt:formatdate />标签
用来将日期类型转换为字符串类型日期
<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 />标签
用来将字符串类型的时间或日期转换成日期时间类型
<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 />标签
用来设置默认时区或将时区存储到属性范围中
复制代码 代码如下:
<fmt:settimezone value="timezone" [var="varname"] [scope="{page|request|session|application}"] />
<fmt:timezone />标签
用来暂时的设定时区
<fmt:timezone value="timezone">
本体内容
</fmt:timezone>
<fmt:setlocale />标签
用来设定用户的区域语言
复制代码 代码如下:
<fmt:setlocale value="locale" [variant="variant"] [scope="{page|request|session|application}"] />
<fmt:requestencoding />标签
设定接收的字符串的编码格式
<fmt:requestencoding value="charsetname" />
<fmt:setbundle />标签
用来设定默认的数据来源,也可以将其存储到一定范围中,供需要时使用
复制代码 代码如下:
<fmt:setbundle basename="basename" [var="varname"] [scope="{page|request|session|application}"] />
<fmt:message />标签
用来从指定的资源文件中通过索引取得值
复制代码 代码如下:
<fmt:message key="messagekey" [bundle="resourcebundle"] [var="varname"] [scope="{page|request|session|application}"] />
<fmt:param />标签
用来传递参数(在从资源文件中取得信息时,可能需要动态设定参数的情况下)
<fmt:param value="messageparameter" />
没有本体内容
<fmt:param value="messageparameter" >有本体内容
参数
</fmt:param>
<fmt:bundle />标签
用来设定数据来源
<fmt:bundle basename="basename" [prefix="prefix"] >
本体内容<fmt:message>
</fmt:bundle>
【说明】:
本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!