JSTL标签

  JSP 标准标签库(JSP Standard Tag Library,JSTL)是一个实现 Web应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断、数据管理格式化、XML 操作以及数据库访问。——百度。

  如果要使用JSTL,则需要将jstl.jar和 standard.jar文件导入到项目中。并且在JSP页面中添加相应的伪指令,例如:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>    
<%@ taglib uri="http://www.bjpowernode.com/myfunctions" prefix="my" %>
  常用的JSTL标签有:

  <c:out>

  <c:if>

  <c:choose>、<c:when>和<c:otherwise>

  <c:forEach>

  <fmt:formatNumber>

  <fmr:formatDate>

  函数库

  实例:

  <c:out>:

<h1>测试JSTL核心库</h1>
	<hr>
	<li>采用c:out标签</li><br>
	hello(使用标签):<c:out value="123"/><br>
	hello(使用标签):<c:out value="hello"/><br>
	hello(使用标签):<c:out value="${hello}"/><br>
	hello(使用EL表达式):${hello }<br>
	hello(default):${hello123 }<br>
	hello(使用缺省值):<c:out value="${hello123}" default="没有值"/><br>
	hello(使用缺省值):<c:out value="${hello123}">没有值</c:out><br>
	welcome(使用EL表达式):${welcome }<br>
	welcome(使用标签,escapeXml=true):<c:out value="${welcome}" escapeXml="true"/><br>
	welcome(使用标签,escapeXml=false):<c:out value="${welcome}" escapeXml="false"/><br>
	<p>

<c:if>:

<li>条件控制标签:c:if</li><br>
	<c:if test="${v1 lt v2}">
		v1小于v2<br>
	</c:if>

<c:choose>、<c:when>和<c:otherwise>:

<li>条件控制标签:c:choose,c:when,c:otherwise</li><br>
	<c:choose>
		<c:when test="${v1 gt v2}">
			v1大于v2<br>
		</c:when>
		<c:otherwise>
			v1小于v2<br>
		</c:otherwise>
	</c:choose>
	<c:choose>
		<c:when test="${empty userList}">
			没有符合条件的数据<br>
		</c:when>
		<c:otherwise>
			存在用户数据<br>
		</c:otherwise>
	</c:choose>

<c:forEach>:

<h3>采用forEach标签</h3>
	<table border="1">
		<tr>
			<td>用户名称</td>
			<td>年龄</td>
			<td>所属组</td>
		</tr>
		<c:choose>
			<c:when test="${empty users}">
				<tr>
					<td colspan="3">没有符合条件的数据</td>
				</tr>
			</c:when>
			<c:otherwise>
				<c:forEach items="${users}" var="user">
					<tr>
						<td>${user.username }</td>
						<td>${user.age }</td>
						<td>${user.group.name }</td>
					</tr>
				</c:forEach>
			</c:otherwise>
		</c:choose>
	</table>	
…………


现在的软件开发注重分层设计,JSTL标签库的使用是为了规范自定义标签的使用和不希望JSP页面中出现java逻辑代码而诞生的。








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值