<span style=
"color: #ff0000;"
>===============================================================================================================
资源文件:</span>
<fmt:message key=
"acctType${l.acctType}"
/>
acctType0=其他
acctType1=个人储蓄账户
acctType2=个人结算账户(储蓄)
acctType3=个人结算账户(对公)
<span style=
"color: #ff0000;"
>===============================================================================================================
格式化时间日期金额等等:</span>
<fmt:formatDate value=
"${isoDate}"
type=
"both"
/>
2004
-
5
-
31
23
:
59
:
59
<fmt:formatDate value=
"${date}"
type=
"date"
/>
2004
-
4
-
1
<fmt:formatDate value=
"${isoDate}"
type=
"time"
/>
23
:
59
:
59
<fmt:formatDate value=
"${isoDate}"
type=
"date"
dateStyle=
"default"
/>
2004
-
5
-
31
<fmt:formatDate value=
"${isoDate}"
type=
"date"
dateStyle=
"short"
/>
04
-
5
-
31
<fmt:formatDate value=
"${isoDate}"
type=
"date"
dateStyle=
"medium"
/>
2004
-
5
-
31
<fmt:formatDate value=
"${isoDate}"
type=
"date"
dateStyle=
"long"
/>
2004
年
5
月
31
日
<fmt:formatDate value=
"${isoDate}"
type=
"date"
dateStyle=
"full"
/>
2004
年
5
月
31
日 星期一
<fmt:formatDate value=
"${isoDate}"
type=
"time"
timeStyle=
"default"
/>
23
:
59
:
59
<fmt:formatDate value=
"${isoDate}"
type=
"time"
timeStyle=
"short"
/>下午
11
:
59
<fmt:formatDate value=
"${isoDate}"
type=
"time"
timeStyle=
"medium"
/>
23
:
59
:
59
<fmt:formatDate value=
"${isoDate}"
type=
"time"
timeStyle=
"long"
/>下午
11
时
59
分
59
秒
<fmt:formatDate value=
"${isoDate}"
type=
"time"
timeStyle=
"full"
/>下午
11
时
59
分
59
秒 CDT
<fmt:formatDate value=
"${date}"
type=
"both"
pattern=
"EEEE, MMMM d, yyyy HH:mm:ss Z"
/>星期四, 四月
1
,
2004
13
:
30
:
00
-
0600
<fmt:formatDate value=
"${isoDate}"
type=
"both"
pattern="d MMM yy, h:m:s a zzzz/>
31
五月
04
,
11
:
59
:
59
下午 中央夏令时
<fmt:formatDate value=
"${question.questiondate}"
type=
"time"
timeStyle=
"full"
pattern=
"yyyy-MM-dd HH:mm"
/>
2009
-
01
-
11
00
:
28
百分数,千分数表示
<fmt:formatNumber value=
"${DoubleVALUE}"
type=
"number"
pattern=
"0.00‰"
/>
0.01
‰
<fmt:formatNumber value=
"${DoubleVALUE}"
type=
"number"
pattern=
"0.00%"
/>
0.20
%
其他数字表示
fmt:formatNumber value=
"123456.7891"
pattern=
"#,#00.0#"
/> --
123
,
456.79
<fmt:formatNumber value=
"123456.7"
pattern=
"#,#00.0#"
/> --
123
,
456.7
<fmt:formatNumber value=
"123456.7"
pattern=
"#,#00.00#"
/> --
123
,
456.70
<fmt:formatNumber value=
"12"
type=
"currency"
pattern=
"$.00"
/> -- $
12.00
<fmt:formatNumber value=
"12"
type=
"currency"
pattern=
"$.0#"
/> -- $
12.0
<fmt:formatNumber value=
"1234567890"
type=
"currency"
/> --$
1
,
234
,
567
,
890.00
(那个货币的符号和当前web服务器的 local 设定有关)
<fmt:formatNumber value=
"123456.7891"
pattern=
"#,#00.0#"
/> --
123
,
456.79
<fmt:formatNumber value=
"123456.7"
pattern=
"#,#00.0#"
/> --
123
,
456.7
<fmt:formatNumber value=
"123456.7"
pattern=
"#,#00.00#"
/> --
123
,
456.70
<fmt:formatNumber value=
"12"
type=
"percent"
/> --
1
,
200
% (type 可以是currency、 number、和percent)。
<fmt:formatNumber value=
"12"
type=
"percent"
/> --
1
,
200
%type 可以是currency、 number、 和percent。
货币表示
1
<fmt:setLocale value=
"ch_CH"
/>
<fmt:formatNumber value=
"${data}"
type=
"currency"
/>
2
<fmt:formatNumber value=
"${doubleValue}"
type=
"number"
pattern=
"¥0.00"
/>
java格式化输出:
DecimalFormat df =
new
DecimalFormat(
"格式"
);
String fmt =df.format(
double
);
符号 意义
0
一个数位
# 一个数位,前导零和追尾零不显示
. 小数点分割位置
, 组分隔符的位置
- 负数前缀
% 用
100
乘,并显示百分号
其他任何符号 在输出字符串中包括指定符号
<%@ page language=
"java"
contentType=
"text/html; charset=gb18030"
%>
<html>
<head>
<title>My JSP
'fmt.jsp'
starting page</title>
</head>
<body>
<c:set var=
"salary"
value=
"3540.2301"
/>
<c:set var=
"total"
value=
"56225.2301"
/>
<fmt:setLocale value=
"en_US"
/>
currency:<fmt:formatNumber value=
"${salary}"
type=
"currency"
currencyCode=
"USD"
/><br>
percent:<fmt:formatNumber value=
"${salary/total}"
type=
"percent"
maxFractionDigits=
"4"
/><br>
<hr>
<jsp:useBean id=
"now"
class
=
"java.util.Date"
></jsp:useBean>
<fmt:setLocale value=
"zh_CN"
/>
full--><fmt:formatDate value=
"${now}"
type=
"both"
dateStyle=
"full"
timeStyle=
"full"
/><br>
long
--><fmt:formatDate value=
"${now}"
type=
"both"
dateStyle=
"long"
timeStyle=
"long"
/><br>
medium--><fmt:formatDate value=
"${now}"
type=
"both"
dateStyle=
"medium"
timeStyle=
"medium"
/><br>
default
--><fmt:formatDate value=
"${now}"
type=
"both"
dateStyle=
"default"
timeStyle=
"default"
/><br>
short
--><fmt:formatDate value=
"${now}"
type=
"both"
dateStyle=
"short"
timeStyle=
"short"
/><br>
</body>
</html>
<span style=
"color: #ff0000;"
>===============================================================================================================
JSP 国际化-格式化货币和日期:</span>
1
.格式化货币
世界上许多国家都有不同的货币格式和数字格式惯例。针对特定的本地化环境正确地格式化和显示货币是本地化的一个重要部分。
<%@ page pageEncoding=
"UTF-8"
%>
<html>
<head>
<title>Currency Formatting</title>
</head>
<body>
<h1>Currency Formatting and locales</h1>
<h3>English, Great Britain</h3>
<fmt:setLocale value=
"en_GB"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>English, USA</h3>
<fmt:setLocale value=
"en_US"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>French, France</h3>
<fmt:setLocale value=
"fr_FR"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>Japanese, Japan</h3>
<fmt:setLocale value=
"ja_JP"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>Korean, Korea</h3>
<fmt:setLocale value=
"ko_KR"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>Spanish, Spain</h3>
<fmt:setLocale value=
"es_ES"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>Arabic, Egypt</h3>
<fmt:setLocale value=
"ar_EG"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<h3>Using Local Numeric Formatting
for
Different Currency</h3>
<h4>English, Great Britan</h4>
<fmt:setLocale value=
"en_GB"
/>
<fmt:formatNumber type=
"currency"
value=
"80000"
/><br/>
<fmt:formatNumber type=
"currency"
value=
"80000"
currencyCode=
"EUR"
/><br/>
</body>
</html>
2
.格式化日期
类似于数字和货币格式化,本地化环境还会影响生成日期和时间的方式。
<%@ page pageEncoding=
"UTF-8"
%>
<html>
<head>
<title>Date Formatting</title>
</head>
<body>
<h1>Date Formatting and locale</h1>
<fmt:timeZone value=
"EST"
>
<jsp:useBean id=
"currentTime"
class
=
"java.util.Date"
/>
<h3>English, Great Britain</h3>
<fmt:setLocale value=
"en_GB"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>English, USA</h3>
<fmt:setLocale value=
"en_US"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>French, France</h3>
<fmt:setLocale value=
"fr_FR"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>Japanese, Japan</h3>
<fmt:setLocale value=
"ja_JP"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>Korean, Korea</h3>
<fmt:setLocale value=
"ko_KR"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>Spanish, Spain</h3>
<fmt:setLocale value=
"es_ES"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
<h3>Arabic, Egypt</h3>
<fmt:setLocale value=
"ar_EG"
/>
<fmt:formatDate type=
"both"
dateStyle=
"full"
timeStyle=
"full"
value=
"${currentTime}"
/><br/>
</fmt:timeZone>
</body>
</html>
<fmt:formatDate>动作的属性
type: 可以是time,date或both。控制是否只生成时间,只生成日期,或者时间日期都生成。
dateStyle: 可以是
short
, medium,
long
或 full(
default
)。控制打印日期使用的具体格式。
timeStyle: 可以是
short
, medium,
long
或 full(
default
)。控制打印时间使用的具体格式。
value: 这是一个java.util.Date 类型的值,用于生成日期和时间。
<span style=
"color: #ff0000;"
>===============================================================================================================
逻辑判断标签:</span>
<c:
if
test=
"${fn:substring(testname, 1, 2)=='n'}"
>
@@@
</c:
if
>
|
fn:contains(string, substring)
|
如果参数string中包含参数substring,返回true
|
fn:containsIgnoreCase(string, substring)
|
如果参数string中包含参数substring(忽略大小写),返回true
|
fn:endsWith(string, suffix)
|
如果参数 string 以参数suffix结尾,返回true
|
fn:escapeXml(string)
|
将有特殊意义的XML (和HTML)转换为对应的XML character entity code,并返回
|
fn:indexOf(string, substring)
|
返回参数substring在参数string中第一次出现的位置
|
fn:join(array, separator)
|
将一个给定的数组array用给定的间隔符separator串在一起,组成一个新的字符串并返回。
|
fn:length(item)
|
返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的字符数。
|
fn:replace(string, before, after)
|
返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方,并返回替换后的结果
|
fn:split(string, separator)
|
返回一个数组,以参数separator 为分割符分割参数string,分割后的每一部分就是数组的一个元素
(不截取空的值 如#####123# var[0]的值会为123)
|
fn:startsWith(string, prefix)
|
如果参数string以参数prefix开头,返回true
|
fn:substring(string, begin, end)
|
返回参数string部分字符串, 从参数begin开始到参数end位置,包括end位置的字符
|
fn:substringAfter(string, substring)
|
返回参数substring在参数string中后面的那一部分字符串
|
fn:substringBefore(string, substring)
|
返回参数substring在参数string中前面的那一部分字符串
|
fn:toLowerCase(string)
|
将参数string所有的字符变为小写,并将其返回
|
fn:toUpperCase(string)
|
将参数string所有的字符变为大写,并将其返回
|
fn:trim(string)
|
去除参数string 首尾的空格,并将其返回
|
如果需要多个fn嵌套
<c:setvar="dateParts"value="${fn:split(dateString, '/')}"/>
...
${fn:replce(dateParts[0], '#','123')}