JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能。

Apache Tomcat安装JSTL 库步骤如下:

  • 从Apache的标准标签库中下载的二进包(jakarta-taglibs-standard-current.zip)。下载地址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/
  • 下 载jakarta-taglibs-standard-1.1.1.zip 包并解压,将jakarta-taglibs-standard-1.1.1/lib/下的两个jar文件:standard.jar和jstl.jar 文件拷贝到/WEB-INF/lib/下。

使用任何库,你必须在每个JSP文件中的头部包含<taglib>标签。

这里只介绍俩种常用的标签。1. 核心标签,2. 时间格式化标签。

一、核心标签。

核心标签是最常用的JSTL标签。引用核心标签库的语法如下:

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

(1)<c:if>

<c:if>标签判断表达式的值,如果表达式的值为真则执行其主体内容。

属性

描述

是否必要

默认值

test

条件

var

用于存储条件结果的变量

scope

var属性的作用域

page

判断是否为空或者是否不为空:

<c:if  test="${empty info.paymentName || info.paymentName eq ''}">
----
</c:if> <c:if test="${not empty info.paymentName && info.paymentName ne ''}">
${info.paymentName}
</c:if>

判断的用法:

<c:if test="${info.status eq 0}">
支付失败
</c:if>
<c:if test="${info.status eq 1}">
已支付
</c:if>

forEash 的应用:

<c:forEach items="${result.newRepaymentLoanList}" var="info">

<span >${info.loanQuota }</span>
<span ><a href="<%=basePath%>project/info/${info.loanId }">查看</a>
</c:forEach>
<c:forEach items="${orderList}" var="info" varStatus="status">

</c:forEach>

二、JSTL格式化标签用来格式化并输出文本、日期、时间、数字。引用格式化标签库的语法如下:

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

<fmt:formatNumber>标签有如下属性:

属性 描述 是否必要 默认值
value 要显示的数字
type NUMBER,CURRENCY,或 PERCENT类型 Number
pattern 指定一个自定义的格式化模式用与输出
currencyCode 货币码(当type="currency"时) 取决于默认区域
currencySymbol 货币符号 (当 type="currency"时) 取决于默认区域
groupingUsed 是否对数字分组 (TRUE 或 FALSE) true
maxIntegerDigits 整型数最大的位数
minIntegerDigits 整型数最小的位数
maxFractionDigits 小数点后最大的位数
minFractionDigits 小数点后最小的位数
var 存储格式化数字的变量 Print to page
scope var属性的作用域 page

如果type属性为percent或number,那么您就可以使用其它几个格式化数字属性。

maxIntegerDigits属性和 minIntegerDigits属性允许您指定整数的长度。

若实际数字超过了maxIntegerDigits所指定的最大值,则数字将会被截断。

有一些属性允许您指定小数点后的位数。minFractionalDigits属性和maxFractionalDigits属性允许您指定小数点后的位数。

若实际的数字超出了所指定的范围,则这个数字会被截断。

数字分组可以用来在每三个数字中插入一个逗号。groupingIsUsed属性用来指定是否使用数字分组。当与minIntegerDigits属性一同使用时,就必须要很小心地来获取预期的结果了。

您或许会使用pattern属性。这个属性可以让您在对数字编码时包含指定的字符。接下来的表格中列出了这些字符。

符号 描述
0 代表一位数字
E 使用指数格式
# 代表一位数字,若没有则显示0
. 小数点
, 数字分组分隔符
; 分隔格式
- 使用默认负数前缀
% 百分数
? 千分数
¤ 货币符号,使用实际的货币符号代替
X 指定可以作为前缀或后缀的字符
' 在前缀或后缀中引用特殊字符

(1)时间格式化。

<fmt:formatDate value="${record.loginTime }" type="both" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
<fmt:formatDate value="${info.lastModified }" type="date" pattern="yyyy-MM-dd HH:mm:ss"/>

(2)金额格式化。

新建一个NumberTest.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <html>
<head>
<title>JSTL fmt:formatNumber Tag</title>
</head>
<body>
<h3>Number Format:</h3>
<!-- 设置 balance的值为 120000.2309 -->
<c:set var="balance" value="120000.2309" />
<p>
Formatted Number (1):
<fmt:formatNumber value="${balance}" type="currency" />
</p>
<p>
Formatted Number (2):
<fmt:formatNumber type="number" maxIntegerDigits="3" value="${balance}" />
</p>
<p>
Formatted Number (3):
<fmt:formatNumber type="number" maxFractionDigits="3" value="${balance}" />
</p>
<p>
Formatted Number (4):
<fmt:formatNumber type="number" groupingUsed="false" value="${balance}" />
</p>
<p>
Formatted Number (5):
<fmt:formatNumber type="percent" maxIntegerDigits="3" value="${balance}" />
</p>
<p>
Formatted Number (6):
<fmt:formatNumber type="percent" minFractionDigits="10" value="${balance}" />
</p>
<p>
Formatted Number (7):
<fmt:formatNumber type="percent" maxIntegerDigits="3" value="${balance}" />
</p>
<p>
Formatted Number (8):
<fmt:formatNumber type="number" pattern="###.###E0" value="${balance}" />
</p>
<p>
Currency in USA :
<fmt:setLocale value="en_US" />
<fmt:formatNumber value="${balance}" type="currency" />
</p>
</body>
</html>
<fmt:formatNumber pattern="#,##0.00" type="number" value="${loanQuota}"></fmt:formatNumber>
<fmt:formatNumber pattern="#,##0.00" type="number" value="${loanQuota}"/>

效果如下:

Number Format:

Formatted Number (1): ¥120,000.23

Formatted Number (2): 000.231

Formatted Number (3): 120,000.231

Formatted Number (4): 120000.231

Formatted Number (5): 023%

Formatted Number (6): 12,000,023.0900000000%

Formatted Number (7): 023%

Formatted Number (8): 120E3

Currency in USA : $120,000.23 

嵌入菜单文件的方式等等:

<%@include file="../meta.jsp"%>
<jsp:include page="../top.jsp">
<jsp:param name="menuShow" value="1" />
<jsp:param name="showIndex" value="3" />
</jsp:include>
<jsp:include page="left.jsp"></jsp:include>

读取 controller 绑定过来的值:

${result.past3RepayCount }

JSP 标准标签库(JSTL)之最常用的JSTL标签总结的更多相关文章

  1. JSTL教程 [JSP 标准标记库]

    JSTL教程- - JSP 标准标记库(JSP Standard Tag Library,JSTL)是一个实现 Web 应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断.数据管理格式 ...

  2. Struts2的标签库(一)——使用Struts2的标签库

    Struts2的标签库(一) --使用Struts2的标签库 1.Struts2的标签库其实就是一个自定义的标签库,所以它也有它的标签处理类和标签库定义文件: 2.和所有自定义标签一样,我们可以找到S ...

  3. JSTL 标准标签库 (JavaServer Pages Standard Tag library, JSTL)

    JSP标准标签库(JavaServer Pages Standard Tag Library,JSTL)是一个定制标签库的集合,用来解决 像遍历Map或集合.条件测试.XML处理,甚至数据 库访问和数 ...

  4. C++标准模板库(STL)常用介绍

    1. 输入输出 C++既可以用C的scanf和printf,也可以用新增的的cin与cout,后者速度慢 1.1 C程序中输入输出 int a; scanf("%d",&a ...

  5. JSP标准标签库(JSTL)--JSTL简介与安装

    对于MVC设计模式来讲,我们一直强调,在一个JSP钟scriptlet代码越少越好,但是只靠以前的概念很难实现,因为标签的开发特别麻烦,所以为了简化标签,也为了让标签更具备一些通用性,所以一般在开发中 ...

  6. JSP 标准标签库(JSTL)(JSP Standard Tag Library)

    [1] JSTL简介    > JSTL是JSP的标准标签库    > JSTL为我们提供了一些常用的标签,供我们日常开发使用(if . if...else .遍历 . 日期格式化)   ...

  7. JSP 标准标签库(JSTL)

    JSP 标准标签库(JSTL) JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签, ...

  8. JSTL(JSP标准标签库)

    JSP标准标签库(JavaServer Pages Tag Library, JSTL)是一个定制JSP标签库的集合,封装了JSP应用的通用核心功能.用来解决像遍历Map或集合.条件测试.XML处理, ...

  9. JSP标准标签库(JSTL)

    JSTL:JSP Standard Tag Library:JSP标准标签库 以下内容引用自http://wiki.jikexueyuan.com/project/jsp/standard-tag-l ...

  10. JSP标准标签库(JSTL)--国际化标签库 fmt

    JSTL中使用fmt.tld作为格式化标签库的定义文件 No. 功能分类 标签名称 描述 1 国际化标签 <fmt:setLocale> 设置一个全局的地区代码 2 <fmt:req ...

随机推荐

  1. 订餐APP第二次sprint+燃尽图

    MY-HR 成员: 角色分配 学号 博客园 团队贡献分 围观其他小组评论 丘惠敏 PM项目经理 201406114203 http://www.cnblogs.com/qiuhuimin/ 21 ht ...

  2. 组合数学 - 波利亚定理 --- poj : 2154 Color

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7873   Accepted: 2565 Description ...

  3. Cocos2dx 3.x包含ext库报错解决

    之前使用cocos2dx 3.6版本中用到了ext库中的一些东西,使用visual studio 2013,编译的时候报错: 无法打开包括文件:“extensions/ExtensionMacros. ...

  4. 重新想象 Windows 8 Store Apps (46) - 多线程之线程同步: Lock, Monitor, Interlocked, Mutex, ReaderWriterLock

    [源码下载] 重新想象 Windows 8 Store Apps (46) - 多线程之线程同步: Lock, Monitor, Interlocked, Mutex, ReaderWriterLoc ...

  5. LeetCode2:Median of Two Sorted Arrays

    题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sor ...

  6. Mac上好用软件集锦

    1. 代码编辑器 TextMate 开源免费 2. 图像处理工具  Seahorse 开源免费 3. 远程Windows桌面连接工具 CoRD 开源免费 4. 办公软件 LibreOffice 开源免 ...

  7. Shiro 整合SpringMVC 并且实现权限管理,登录和注销

    Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Security做的功能强大 ...

  8. javascript 之注意url特殊字符限制

    引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器url参数操作的时候,经常会用到encodeURIComponent()和decodeURIComponent()以及encode ...

  9. CKEditor与CKFinder的配置

    CKEditor与CKFinder的配置使用(一) 将CKEditor 与 CKFinder 的包含在项目中 从http://cksource.com网站上下载CKEditor与CKFinder,并将 ...

  10. JavaScript this特性,静态方法 和实例方法,prototype

    <script type="text/javascript"> function logs(str) { document.write(str + "< ...