JSTL学习——核心标签和格式化标签

​此博客为个人学习所用。

导入JSTL库

在官方下载地址下载包并解压,解压后将/lib/下的两个jar包(standard.jar 和 jstl.jar 拷贝到 /WEB-INF/lib/ 下)

并且在web.xml文件中添加下列配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <jsp-config>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
    <taglib-location>/WEB-INF/fmt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/fmt-rt</taglib-uri>
    <taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core-rt</taglib-uri>
    <taglib-location>/WEB-INF/c-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/sql</taglib-uri>
    <taglib-location>/WEB-INF/sql.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/sql-rt</taglib-uri>
    <taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/x</taglib-uri>
    <taglib-location>/WEB-INF/x.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/x-rt</taglib-uri>
    <taglib-location>/WEB-INF/x-rt.tld</taglib-location>
    </taglib>
    </jsp-config>
</web-app>

同时,在使用任何库的时候,必须在每个JSP文件中的头部都包含标签

核心标签库

引入核心标签库:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

标签描述
<c:url>使用可选的参数来创造一个URL
<c:redirect>重定向至一个新的URL.
<c:param>用来给包含或重定向的页面传递参数
<c:forTokens>根据指定的分隔符来分隔内容并迭代输出
<c:forEach>基础迭代标签,接受多种集合类型
<c:import>检索一个绝对或相对 URL,然后将其内容暴露给页面
<c:otherwise><c:choose>的子标签,接在<c:when>标签后,当<c:when>标签判断为false时被执行
<c:when><c:choose>的子标签,用来判断条件是否成立
<c:choose>本身只当做<c:when>和<c:otherwise>的父标签
<c:if>与我们在一般程序中用的if一样
<c:catch>用来处理产生错误的异常状况,并且将错误信息储存起来
<c:remove>用于删除数据
<c:set>用于保存数据
<c:out>用于在JSP中显示数据,就像<%= … >
格式化标签

引用格式化标签库:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

标签描述
fmt:formatNumber使用指定的格式或精度格式化数字
fmt:parseNumber解析一个代表着数字,货币或百分比的字符串
fmt:formatDate使用指定的风格或模式格式化日期和时间
fmt:parseDate解析一个代表着日期或时间的字符串
fmt:bundle绑定资源
fmt:setLocale指定地区
fmt:setBundle绑定资源<c:when>标签判断为false时被执行
fmt:timeZone指定时区
fmt:setTimeZone指定时区
fmt:message显示资源配置文件信息
fmt:requestEncoding设置request的字符编码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值