现在的位置: 首页 > 综合 > 正文

JSTL解析——007——fmt标签库02

2013年02月20日 ⁄ 综合 ⁄ 共 1347字 ⁄ 字号 评论关闭

各位亲们,近期事情比较多,没更新,come on!

1、<fmt:bundle>/<fmt:message>/<fmt:param>资源国际化标签

java中使用ResourceBundle类解决i18n的问题,简单的说就是把所有的中文提示都放在message_zh_CN.propertyies文件里,当中文系统访问程序时自动显示中文文件里的提示

在JSTL标签库中使用bundle、message、param来实现该功能

<fmt:bundle basename="messages">
<fmt:message key=""prompt.hello">
<fmt:param value="Heloworld"></fmt:param>
</fmt:message>
<fmt:bundle>

各属性解析:basename是指定了资源文件的名称(messages.properties)所有类似messages_XX.properties都被加载

bundle标签内部使用message标签显示资源文件,key属性对应子牙properties文件资源的key属性,如果资源能够使用参数则使用param标签传入参数

大家是不是对“prompt.hello”不明白,

messages.properties

prompt.hello=hello;

这下是不是明白???

2、<fmt:setBundle>标签

bundle只对内部标签有效,而setBundle对所有的标签有效

<fmt:setBundle basename="messages" var="resource" scoper="request">
<fmt:message key=""prompt.hello" bundle=“${resource}”>
<fmt:param >Heloworld</fmt:param>
</fmt:message>
<fmt:setBundle>

看到区别没,把资源映射到ar指定的变量中去,scope是作用域

3、<fmt:formatNumber>显示不同地区的各种数据格式

前面已经降到了各国数字表示的差异,比如:1,005在不同的国家得出不同的值,美国是1千零五,德国是一点零零五,差别是不是很大

这时候formatNumber作用就显现了,它能根据不同的Locale输出不同的格式

<fmt:formatNumber value="${number}" type="number" maxIntegerDigits="3"/>

formatNumber包含的属性比较多,value要被格式的数字

type声明数字的类型(number,currency,percent),

pattern 数字格式(‘0000.00’等),

currencySymbol 输出货币符号,currencyCode 货币代码、groupingUsed 是否输出分隔符、

maxIntegerDigits 整数位数的最大值,超过就截掉高位 minIntegerDigits 整数位数的最小值 不够则高位补0

 maxFractionDigits  小数位数的最大值 超过则四舍五入minFractionDigits 小数位数最小值 不够则低位补0

var  将格式化后的数字存储到var标量中   scope 声明变量作用域

抱歉!评论已关闭.