您的位置:首页 > Web前端 > JavaScript

JSP中常用的JSTL fmt(format格式化)标签用法整理

2016-04-14 00:00 781 查看
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>


您可能感兴趣的文章:

JSP中一些JSTL核心标签用法总结
JSP中使用JSTL按不同条件输出内容的方法
JSP入门教程之客户端验证、常用输出方式及JSTL基本用法
jsp 使用jstl实现翻页实例代码
jsp中使用jstl导入html乱码问题解决方法
JSP和JSTL获取服务器参数示例
关于jsp页面使用jstl的异常分析
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JSP 格式化