
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<jsp-config>
<taglib>
<taglib-uri>jstl-c</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>jstl-fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>jstl-fn</taglib-uri>
<taglib-location>/WEB-INF/fn.tld</taglib-location>
</taglib>
</jsp-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
taglib.jsp
<%@taglib uri="jstl-c" prefix="c" %>
<%@taglib uri="jstl-fmt" prefix="fmt" %>
<%@taglib uri="jstl-fn" prefix="fn" %>
设置语言环境的标签setLocale
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>ftm:setLoacle标记的使用</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2 align="center">用于指定所使用的语言环境</h2><br>
<h3>value: 语言环境的字符串,或java.util.Locale的对象</h3><br>
<h3>scope: 指定作用的范围</h3><br>
<h3>variant: 针对特定的平台或供应商定制语言环境</h3><br>
<br><br>
<h2>执行下面的代码,将忽略用户浏览器设置中所指定的语言</h2>
<fmt:setLocale value="zh_CN" scope="session"/>
</body>
</html>
设置时区setTimeZone
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>fmt:setTimeZone标记的使用</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2 align="center">设置时区的标记</h2>
<h3>value: 时区名或java.util.TimeZone对象</h3>
<h3>scope: 作用的范围</h3>
<h3>var: 保存TimeZone对象的变量的名称</h3>
<fmt:setTimeZone value="GMT+8" scope="session" />
<fmt:formatDate type="both" value="<%=new java.util.Date() %>"/><br>
</body>
</html>
另一个设置时区的timeZone
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>fmt:timeZone标记的使用</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2 align="center">设置时区的标记,只对所包含的内容有效</h2><br>
<fmt:formatDate type="both" value="<%=new java.util.Date() %>"/><br>
<fmt:timeZone value="GMT+8">
<fmt:formatDate type="both" value="<%=new java.util.Date() %>"/>
</fmt:timeZone>
</body>
</html>
formateDate
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>fmt:formateDate标记的使用</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2 align="center">格式化和显示日期</h2><br>
<h3>value: 指定日期和时间</h3>
<h3>type: 设置显示的是时间还是日期,有效取值是time,date或both,默认的是date</h3>
<h3>dateStyle: 设置如何格式化日期信息。有效值是:default,short,medium,long和full</h3>
<h3>timeStyle: 设置如何格式化时间信息。有效值是:default,short,medium,long和full</h3>
<h3>pattern: 日期和时间的样式yy-MM-dd HH:mm:ss</h3>
<h3>timeZone: 设置显示那个时区的日期和时间,要是没有就使用fmt:timeZone设置的</h3>
<h3>var: 保存格式化的时间或日期,要是没这属性就输出时间或日期的结果</h3>
<h3>scope: 作用的范围</h3>
<fmt:formatDate type="both" value="<%=new java.util.Date() %>" pattern="yy-MM-dd HH:mm:ss"/><br>
<fmt:timeZone value="GMT+8">
<fmt:formatDate type="both" value="<%=new java.util.Date() %>" />
</fmt:timeZone>
</body>
</html>
formateNumber
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>fmt:formateNumber标记的使用</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h2 align="center">格式化和显示数字</h2><br>
<h3>value: 指定格式化的数值</h3>
<h3>type: 指明要对哪种类型的数值进行格式化,有效取值是number,currency和percent</h3>
<h3>pattern: 数字格式化的样式</h3>
<h3>groupingUsed: 设置是否要对小数点前面的数字进行分组。例如,将较大数的每三个数字分为一组</h3>
<h3>var: 保存格式化的数字的名称,要是没这属性就直接在页面输出</h3>
<h3>scope: 作用的范围</h3>
<c:set value="1234567890.12345678" var="number" />
默认方式的格式化数字<fmt:formatNumber type="number" value="${number}" /><br>
数字不分组<fmt:formatNumber type="number" groupingUsed="false" value="${number}" /><br>
整数部分最大三位<fmt:formatNumber type="number" maxIntegerDigits="3" value="${number}" /><br>
整数部分最小取12位<fmt:formatNumber type="number" minIntegerDigits="12" value="${number}" /><br>
小数部分最大取2位<fmt:formatNumber type="number" maxFractionDigits="2" value="${number}" /><br>
小数部分最小取5位<fmt:formatNumber type="number" minFractionDigits="5" value="${number}" /><br>
格式化货币数字<fmt:formatNumber type="currency" value="${number}" /><br>
格式化百分比数字<fmt:formatNumber type="percent" value=".348" /><br>
</body>
</html>