JSTL

<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %><%--
  User: 丁帅帅
  Date: 21/05/30
  Time: 11:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
      <c:if test="true">
          <h1>我是真的......</h1>
      </c:if>
      <br>
      <%
          List list=new ArrayList();
          list.add("aaaa");
          request.setAttribute("list",list);
          request.setAttribute("number",4);
      %>
      <c:if test="${not empty list}">
           遍历集合....
      </c:if>
<br>
     <c:if test="${number%2!=0}">
         ${number}为奇数
     </c:if>

    <c:if test="${number%2==0}">
       ${number}为偶数
    </c:if>

</body>
</html>

  

<%--
  User: 丁帅帅
  Date: 21/06/02
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setAttribute("number",3);
%>
<c:choose>
    <c:when test="${number==1}">星期一</c:when>
    <c:when test="${number==2}">星期二</c:when>
    <c:when test="${number==3}">星期三</c:when>

    <c:otherwise>数字输入有误</c:otherwise>
</c:choose>
</body>
</html>

  

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  User: 丁帅帅
  Date: 21/06/02
  Time: 15:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
     <c:forEach begin="1" end="10" var="i" step="2" varStatus="s">
         ${i}<h3>${s.index}</h3><h4>${s.count}</h4><br>
     </c:forEach>

<hr>

<%
    List list=new ArrayList();
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");

    request.setAttribute("list",list);
%>

<c:forEach items="${list}" var="str" varStatus="s">
    ${s.index} ${s.count} ${str}<br>
</c:forEach>


</body>
</html>

  

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ding.domain.User" %>
<%@ page import="java.util.Date" %><%--
  User: 丁帅帅
  Date: 21/06/02
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    List list=new ArrayList();
    list.add(new User("张三",23,new Date()));
    list.add(new User("李四",24,new Date()));
    list.add(new User("王五",25,new Date()));

    request.setAttribute("list",list);
%>
<table border="1" width="500" align="center">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>生日</th>
    </tr>
    <c:forEach items="${list}" var="user" varStatus="s">
        <c:if test="${s.count%2!=0}">
            <tr bgcolor="red">
                <td>${s.count}</td>
                <td>${user.name}</td>
                <td>${user.age}</td>
                <td>${user.birStr}</td>
            </tr>
        </c:if>

        <c:if test="${s.count%2==0}">
            <tr bgcolor="aqua">

                <td>${s.count}</td>
                <td>${user.name}</td>
                <td>${user.age}</td>
                <td>${user.birStr}</td>
            </tr>
        </c:if>
    </c:forEach>

</table>
</body>
</html>

  

posted @ 2021-06-02 17:15  丁帅帅dss  阅读(35)  评论(0)    收藏  举报