jstl基础语句

简介: jstl基础语句

文章目录


jstl:

if语句

forEach语句

choose when otherwise语句


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>


相关文章
|
11天前
EL表达式和Jstl常见的用法
EL表达式和Jstl常见的用法
16 0
|
11天前
|
Java 数据库
el表达式与jstl的用法
el表达式与jstl的用法
10 0
|
11天前
|
机器学习/深度学习 算法 前端开发
深入浅出剖析EL表达式和JSTL
深入浅出剖析EL表达式和JSTL
30 0
深入浅出剖析EL表达式和JSTL
|
8月前
jstl编程案例一
jstl编程案例一
34 0
|
XML SQL JavaScript
JavaWeb - JSTL、EL 表达式
JavaWeb - JSTL、EL 表达式
171 0
JavaWeb - JSTL、EL 表达式
【EL与JSTL表达式】学习JSP之后,这是你不得不知道的技术
之前我们已经完成了对JSP的学习,但是还有一些其他的东西我们必须得知道,今天我们来学习EL与JSTL表达式。它们将简化JSP的书写并且使得JSP更加强大。但是如果你对JSP一无所知的话建议你先去看一下之前入门JSP的文章。
【EL与JSTL表达式】学习JSP之后,这是你不得不知道的技术
|
Java
JavaWeb--EL表达式&JSTL 标签库(二)
JavaWeb--EL表达式&JSTL 标签库(二)
82 0
JavaWeb--EL表达式&JSTL 标签库(二)
|
Java
JavaWeb--EL表达式&JSTL 标签库(一)
JavaWeb--EL表达式&JSTL 标签库(一)
79 0
JavaWeb--EL表达式&JSTL 标签库(一)
|
XML 开发框架 Java
自定义JSTL函数
由于 jstl 函数 字符串替换不支持正则表达式 所以想用java String的 replaceAll进行替换 需要自定义 jstl函数
98 0
自定义JSTL函数