JSTL标签库学习笔记 一、概述

JSTL标签库的使用是为类弥补html表的不足,规范自定义标签的使用而诞生的。在告别modle1模式开发应用程序后,人们开始注重软件的分层设计,不希望在jsp页面中出现java逻辑代码,同时也由于自定义标签的开发难度较大和不利于技术标准化产生了自定义标签库。JSTL标签库可分为5类:

1、核心标签库

2、I18N格式化标签库

3、SQL标签库

4、XML标签库

5、函数标签库


1、核心标签库

JSTL的核心标签库标签共13个,从功能上可以分为4类:表达式控制标签、流程控制标签、循环标签、URL操作标签。

    使用这些标签能够完成JSP页面的基本功能,减少编码工作。

    (1)表达式控制标签:out标签、set标签、remove标签、catch标签。

    (2)流程控制标签:if标签、choose标签、when标签、otherwise标签。

    (3)循环标签:forEach标签、forTokens标签。

    (4)URL操作标签:import标签、url标签、redirect标签。

     JSP页面引入核心标签库的代码为:

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

2、I18N格式标签库

JSTL标签提供了对国际化(I18N)的支持,它可以根据发出请求的客户端地域的不同来显示不同的语言。同时还提供了格式化数据和日期的方法。实现这些功能需要I18N格式标签库(I18N-capable formation tags liberary)。引入该标签库的方法为:

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

I18N格式标签库提供了11个标签,这些 标签从功能上可以划分为3类如下:

1)数字日期格式化。formatNumber标签、formatData标签、parseNumber标签、parseDate标签、timeZone标签、setTimeZone标签。

2)读取消息资源。bundle标签、message标签、setBundle标签。

3)国际化。setlocale标签、requestEncoding标签。

3、SQL标签库

JSTL提供了与数据库相关操作的标签,可以直接从页面上实现数据库操作的功能,在开发小型网站是可以很方便的实现数据的读取和操作。本章将详细介绍这些标签的功能和使用方法。

SQL标签库从功能上可以划分为两类:设置数据源标签、SQL指令标签。

引入SQL标签库的指令代码为:

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

4、XML标签库

JSTL 提供了操作 xml 文件的标签库,使用 xml 标签库可以省去使用 Dom SAX 标签库的繁琐,能轻松的读取 xml 文件的内容。

(1) XML核心标签库         <x:parse>标签、<x:out>标签、<x:set>标签

 (2) XML流程控制            <x:if>、<x:choose><x:when><x:otherwise>标签

 (3) xml的文件转换    <x:transform>标签、<x:param>标签

5、JSTL函数(JSTL Functions)

JSTL包括一些标准功能,其中大部分是常见的字符串操作函数。以下是在JSP的语法包函JSTL函数库:

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

以下是JSTL函数列表:

Function Description
fn:contains()Tests if an input string contains the specified substring.
fn:containsIgnoreCase()Tests if an input string contains the specified substring in a case insensitive way.
fn:endsWith()Tests if an input string ends with the specified suffix.
fn:escapeXml()Escapes characters that could be interpreted as XML markup.
fn:indexOf()Returns the index withing a string of the first occurrence of a specified substring.
fn:join()Joins all elements of an array into a string.
fn:length()Returns the number of items in a collection, or the number of characters in a string.
fn:replace()Returns a string resulting from replacing in an input string all occurrences with a given string.
fn:split()Splits a string into an array of substrings.
fn:startsWith()Tests if an input string starts with the specified prefix.
fn:substring()Returns a subset of a string.
fn:substringAfter()Returns a subset of a string following a specific substring.
fn:substringBefore()Returns a subset of a string before a specific substring.
fn:toLowerCase()Converts all of the characters of a string to lower case.
fn:toUpperCase()Converts all of the characters of a string to upper case.
fn:trim()Removes white spaces from both ends of a string.





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值