jstl基础语句

jstl:

if语句

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>if 标签</title>
</head>
<body>
<%--    if 标签
       格式
         <c:if text="<boolean>" var="<String>" scope="<String>">
             ....
         </c:if>
         --%>


<%
    request.setAttribute("num",10);
%>
     <c:if test="${num}">
    数值大于0
     </c:if>
     <c:if test="${num > 100}" var="flag" scope="request"></c:if>
     ${flag} -- ${request.flag}

</body>
</html>

forEach语句

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>forEach</title>
</head>
<body>
<%--   相当于for(int i = 0; i<10; i++)--%>
    <c:forEach var="i" begin="1" end="10" step="2">
        ${i} &nbsp;
    </c:forEach>




<%
    List<String> list = new ArrayList<>();
    for (int i = 0; i<10;i++){
        list.add("A:" + i);
    }

    pageContext.setAttribute("li",list);
//    相当于:
//    for (String li : list){
//        out.print(li);
//    }
%>

  <c:forEach items="${li}" var="item">
      ${item} &nbsp;
  </c:forEach>


<table align="center" width="800" border="1" style="border-collapse: collapse">
    <tr>
        <th>名称</th>
        <th>当前成员的下标</th>
        <th>当前成员的循环数</th>
        <th>是否第一次被循环</th>
        <th>是否最后一次循环</th>
    </tr>
    <c:forEach items="${li}" var="item" varStatus="itemp">
        <tr>
            <td>${item}</td>
            <td>${item}</td>
            <td>${item}</td>
            <td>${item}</td>
            <td>${item}</td>
        </tr>
    </c:forEach>
</table>




<%
    List<User> userList = new ArrayList<>();
    for (int i = 0;i<3;i++){
        User user1 = new User(1,"gagu","duygauhi");
        userList.add(user1);
        request.setAttribute("userList",userList);
    }


%>
    <c:if test="${!empty userList}">
<table align="center" width="800" border="1" style="border-collapse: collapse">
    <tr>
        <th>用户编号</th>
        <th>用户名称</th>
        <th>用户密码</th>
        <th>用户操作</th>
    </tr>
    <c:forEach items="${userList}" var="user">
    <tr>
        <td>${user.userId}</td>
        <td>${user.uname}</td>
        <td>${user.upwd}</td>
        <td><button>修改</button></td>
    </tr>
    </c:forEach>
    </c:if>

</body>
</html>

choose when otherwise语句

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>choose when otherwise</title>
</head>
<body>
<%
    request.setAttribute("score",80);
%>
    <c:choose>
        <c:when test="${score <60}">
            你个渣渣
        </c:when>
        <c:when test="${score>=60 && score<=80}">
            可以可以
        </c:when>
        <c:otherwise>
            牛逼
        </c:otherwise>
    </c:choose>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值