JSTL核心实例

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>Test JSTL</title>
  </head>
  
  <body>
  	<!-- 赋值 -->
    <c:set var="name" value="zhang" scope="request"> 
    </c:set>
    
    <!-- EL显示内容 -->
    ${requestScope.name }<br />
    
    <!-- JSTL显示内容 -->
    <c:out value="${requestScope.name}"></c:out> <br />
    
    <!-- EL三元运算 -->
    ${empty(requestScope.name) ? 'name is null' : requestScope.name } <br />
    
    <!-- JSTL输出控制 -->
    <c:out value="${requestScope.name}" default="name is null"></c:out> <br />
    
    <!-- JSTL if 语句 -->
    <c:if test="${empty requestScope.name}" var="aa" scope="page">
    	not null	<br />
    </c:if>
    <c:if test="${!aa}">
    	is null		<br />
    </c:if>
    
    <!-- JSTL删除元素 -->
    <c:remove var="name" scope="request"></c:remove>
    
    <!-- JSTL多重分支 -->
    <c:set var="money" value="5000" scope="request">
    </c:set>
    ${requestScope.money }
    <c:choose>
    	<c:when test="${money >= 1000}">
    		大于1000<br />
    	</c:when>
    	<c:when test="${money <= 1000 && money >=500}">
    		小于1000大于500<br/>
    	</c:when>
    	<c:otherwise>
    		其他情况<br/>
    	</c:otherwise>
    </c:choose>
    
    <!-- JSTL多重分支判断字符串 -->
    <c:set var="uName" value="aaa" scope="request">
    </c:set>
    
    <c:choose>
    	<c:when test="${uName == 'lyq'}">
    		lyq<br/>
    	</c:when>
    	<c:when test="${uName eq 'aaa'}">
    		aaa
    	</c:when>
    	<c:otherwise>
    		不知道
    	</c:otherwise>
    </c:choose>
    <br/>
    
    <!-- JSTL循环 -->
    <c:forEach begin="1" end="10" varStatus="aaa">
    	${aaa.index } ++ ${aaa.count }<br/>
    </c:forEach>
    
    <br/>
    <!-- JSTL循环遍历集合 -->
    <table border="1">
    	<tr>
    	<th>姓名</th>
    	<th>年龄</th>
    	<th>性别</th>
    	</tr>
    	<c:forEach var="stu" items="${requestScope.list}">
	    	<tr>
	    		<td>${stu.name }</td>
	    		<td>${stu.age }</td>
	    		<td>${stu.sex }</td>
	    	</tr>
    	</c:forEach>
    </table>
       
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值