版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luyaran/article/details/82143887
<fmt:setBundle>标签用来载入一个资源束,然后将它存储在作用域中已命名的变量或bundle配置变量中,语法如下:
<fmt:setBundle baseName="<string>" var="<string>" scope="<string>"/>
<fmt:setBundle>标签有如下属性:
属性 | 描述 | 是否必要 | 默认值 |
---|---|---|---|
basename | 资源束家族基础名称,暴露给作用域变量或配置变量 | 是 | 无 |
var | 存储新资源束的变量 | 否 | Replace default |
scope | 变量的作用域 | 否 | Page |
实例操作如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>JSTL fmt:setBundle 标签</title>
</head>
<body>
<fmt:setLocale value="en"/>
<fmt:setBundle basename="com.luyaran.Example" var="lang"/>
<fmt:message key="count.one" bundle="${lang}"/><br/>
<fmt:message key="count.two" bundle="${lang}"/><br/>
<fmt:message key="count.three" bundle="${lang}"/><br/>
</body>
</html>
<fmt:timeZone>标签用来指定时区,供其它标签使用,语法如下:
<fmt:setLocale value="<string>" variant="<string>" scope="<string>"/>
<fmt:timeZone>标签有如下属性:
属性 | 描述 | 是否必要 | 默认值 |
---|---|---|---|
value | 时区 | 是 | 无 |
实例如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<title>JSTL fmt:timeZone 标签</title>
</head>
<body>
<c:set var="now" value="<%=new java.util.Date()%>" />
<table border="1" width="100%">
<tr>
<td width="100%" colspan="2" bgcolor="#0000FF">
<p align="center">
<b>
<font color="#FFFFFF" size="4">Formatting:
<fmt:formatDate value="${now}" type="both"
timeStyle="long" dateStyle="long" />
</font>
</b>
</p>
</td>
</tr>
<c:forEach var="zone"
items="<%=java.util.TimeZone.getAvailableIDs()%>">
<tr>
<td width="51%">
<c:out value="${zone}" />
</td>
<td width="49%">
<fmt:timeZone value="${zone}">
<fmt:formatDate value="${now}" timeZone="${zn}"
type="both" />
</fmt:timeZone>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
运行结果如下:
好啦,本次记录就到这里了。
如果感觉不错的话,请多多点赞支持哦。。。