jsp_JSTL使用

包: taglibs-standard-impl-1.2.5.jar webapps\examples\WEB-INF\lib
taglibs-standard-spec-1.2.5.jar webapps\examples\WEB-INF\lib

JSTL(Java标准标签库)
使用JSTL的准备
1.加入jar包:
在Tomcat中的webapps\examples\WEB-INF\lib
2.通过JSP的taglib指令,引入标签库
<%@ taglib uri=“http://java.sun.com/jsp/jstl/…” prefix=“c” %> //prefix取别名

  标签库		URI					前缀	   使用模式

核心标签库		http://java.sun.com/jsp/jstl/core	c	   <c:tagname...>
国际化标签		http://java.sun.com/jsp/jstl/fmt	fmt	   <fmt:tagname...>
SQL标签库		http://java.sun.com/jsp/jstl/sql	sql	   <sql:tagname...>
XML标签库		http://java.sun.com/jsp/jstl/xml	x	   <x:tagname...>
函数标签库		http://java.sun.com/jsp/jstl/function	fn	   <fn:tagname...>

核心标签库:
常用标签:
if:
属性:
test 必须属性,接受boolean表达式
如果表达式为true,则显示if标签体内容,如果为false,则不显示标签体内容
一般情况下,test属性值会结合el表达式一起使用

       注意:c:if标签没有else情况,想要else情况,则可以在定义一个c:if标签


    <c:if test="${3>2}">
	    ${empty list}
	</c:if>
		
	<c:if test="${num>10}" var="result" scope="page" />  //将结果放到pageContext中
	
switch:
	<c:choose>
	<c:when test="${num>10}" >大于10</c:when>
	<c:when test="${num==10}">${num}</c:when>
	<c:otherwise>小于</c:otherwise>
	</c:choose>

foreach:
   
   属性:		            
         begin:开始值
           end:结束值
           var:临时变量
          step:步长
     varStatus: 循环状态对象
	index: 容器中元素的索引,从0开始
	count: 循环次数,从1开始
  
   例:
     <c:forEach items="${lists}" var="esl" varStatus="">
        ${esl.uname}<br>
     </c:forEach>	

国际化标签:
<fmt:formatDate value="${date}" pattern=“yyyy-MM-dd HH:mm:ss” />

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值