JSTL国际化标签库--fmt与函数库--fn

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

fmt:setLocale 设定用户所在的区域;

<body>
<%
    pageContext.setAttribute("date",new Date());
%>
中文日期:
<fmt:setLocale value="zh_CN"/>
<fmt:formatDate value="${date }"/>
<hr/>
英文日期:
<fmt:setLocale value="en_US"/>
<fmt:formatDate value="${date }"/>
</body>
View Code

fmt:formatDate 对日期进行格式化;

<body>
<!-- value:数值 ;  type:数值类型;  pattern:格式 -->
<%
    Date date=new Date();
    pageContext.setAttribute("date",date);
%>
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
<hr/>
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd"/>
</body>
View Code

fmt:requestEncoding 设置所有的请求编码;

<fmt:requestEncoding value="UTF-8"/>


fmt:bundle fmt:message 读取国际化资源;

<body>
<fmt:setLocale value="zh_CN"/>
<fmt:bundle basename="info">
    <fmt:message key="name" var="userName"/>
</fmt:bundle>
<h2>姓名:${userName }</h2>
<fmt:bundle basename="info">   <!-- 读取info_*.properties资源文件 -->
    <fmt:message key="info" var="infomation">    <!-- 把资源文件中info 赋给 infomation 显示 -->
        <fmt:param value="<font color='red'>小锋</font>"/>   <!-- 把值插入资源文件指定位置显示 -->
    </fmt:message>
</fmt:bundle>
<h2>信息:${infomation }</h2>
<hr/>
<fmt:setLocale value="en_US"/>
<fmt:bundle basename="info">
    <fmt:message key="name" var="userName"/>
</fmt:bundle>
<h2>姓名:${userName }</h2>
<fmt:bundle basename="info">
    <fmt:message key="info" var="infomation">
        <fmt:param value="<font color='red'>小锋</font>"/>
    </fmt:message>
</fmt:bundle>
<h2>信息:${infomation }</h2>
</body>

------------------info_en_US.properties-------------------------------

name=xiaofeng
info=Current user{0}:Welcome to use our system

------------------info_zh_CN.properties-------------------------------
name=小锋
info=当前用户{0}:欢迎使用本系统
View Code

fmt:formatNumber 格式化数字; (简单举个例子,用到上网查详细资料)

<body>
<!-- value:数值 ;  type:数值类型;  pattern:格式 -->
<fmt:formatNumber value="12" type="currency" pattern="$.00"/> 
<fmt:formatNumber value="12" type="currency" pattern="$.0#"/>
<fmt:formatNumber value="1234567890" type="currency"/> 
<fmt:formatNumber value="123456.7891" pattern="#,#00.0#"/>
</body>
View Code

fmt:timeZone 设置临时时区;

<body>
<!-- value:数值 ;  type:数值类型;  pattern:格式 -->
<%
    Date date=new Date();
    pageContext.setAttribute("date",date);
%>
当前时间:<fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
<hr/>
格林尼治时间:
<fmt:timeZone value="GMT">
   <fmt:formatDate value="${date }" pattern="yyyy-MM-dd HH:mm:ss"/>
</fmt:timeZone>
</body>
View Code

 

JSTL 函数标签库

下面列举几个函数,其他的见tld文件

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<body>
<%
    pageContext.setAttribute("info","www.java1234.com");
%>
<h2>查找java1234位置:${fn:indexOf(info,"java1234")}</h2>
<h2>判断java1234是否存在:${fn:contains(info,"java1234")}</h2>
<h2>截取:${fn:substring(info,0,5)}</h2>
<h2>拆分:${fn:split(info,".")[1]}</h2>
</body>
View Code

 

JSTL XML标签库 (不列举了,用的时候查)

x:parse 解析 xml;
x:out 输出 xml 文件的内容;
x:set 把 xml 读取的内容保存到指定的属性范围;
x:if 判断指定路径的内容是否符合判断的条件;
x:choose x:when x:otherwise 多条件判断;
x:forEach 遍历

 

JSTL SQL标签库

Sql:setDataDource 设置 JDBC 连接;
sql:query 数据库查询操作;
Sql:update 数据库添加,修改,删除操作;
Sql:transaction 数据库事务;

posted @ 2017-03-04 00:19  SKYisLimit  阅读(139)  评论(0)    收藏  举报