当前位置:编程学习 > JS >>

JSTL解析——006——fmt标签库01

前面主要讲解core标签库,今天开始讲解fmt标签库:fmt是辅助性功能标签,fmt的全称是format
1、<fmt:requestEncoding>标签
requestEncoding标签是用来设置request编码的,作用相当于request.setCharacterEncoding("XX");它的使用非常简单,只有value一个属性
<fmt:requestEncoding value="GBK"/>
2、<fmt:setLocale>标签
setLocale标签的作用是显示所有地区的数据格式,其中Locale是本地化的意思,它的作用主要是为了解决不同地区和国家对对统一内容显示的不同形式
(时间显示问题,中国2013年09月12日,英国是NoverNumber 12,2013 11:12:12 AM等),为了方便大家
[html]  
<%  
request.setAttribute("localeList",Locale.getAvailableLocales());//先获取各国显示格式,存放到localList中去  
%>  
<jsp:useBean id="date" class="java.util.Date"/>  
<c:forEach var="locale" items="${localList}">  
<fmt:setLocale value="${locale}"/>  
${locale.displayName}  
<fmt:formatDate value="${date}" type="both"/>  
</c:forEach>  
没循环一次显示的时间样式是有区别的
3、<fmt:timeZone>标签
timeZone显示全球时间,时间除了所Locale影响(时间的显示格式)之外,还受时区影响(时间的值),
[html]  
<%  
request.setAttribute("localeList",IimeZone.getAvailableIDs());//先获取时区,存放到localList中去  
%>  
<jsp:useBean id="date" class="java.util.Date"/>  
<c:forEach var="ID" items="${localList}">  
<fmt:timeZone value="${ID}">  
${locale.displayName}  
<fmt:formatDate value="${date}" type="both" timezone="${ID}"/>  
[html] view plaincopyprint?
</fmt:timeZone  
</c:forEach>  
[html]  
值得注意的timeZone只对标签内部的代码起作用,  
4、<fmt:setTimeZone>标签
setTimeZone是对timeZone标签的补充,可以设置全局的timeZone,只有value属性一个
<fmt:setTimeZone value="GMT-8">也可以和timeZone取值一样,但是这时候就是全局的作用了
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,