牧码的羊
发布于 2025-02-20 / 17 阅读
0
0

JSTL 核心常用标签样例

<%--  
 Created by IntelliJ IDEA. User: meyj Date: 2025/1/14 Time: 09:40 To change this template use File | Settings | File Templates.--%>  
<%@ page contentType="text/html;charset=UTF-8" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
  
<html>  
<head>  
 <title>JSTL-EL</title>  
</head>  
<body>  
<%  
  String aaa = "bbb";  
  request.setAttribute("items", new int[]{5, 4, 3, 2, 1});  
%>  
<c:set var="tokenItems" value="6,7,8,9" scope="request"/>  
<c:set var="salary" value="${2000*2}" scope="page"/>  
  
<p><c:out value="你的工资为: ${salary}"/></p>  
  
<c:if test="${salary > 0}">  
    <p>我的工资为 2: ${salary}</p>  
</c:if>  
  
<p>  
  <c:choose>  
        <c:when test="${salary <= 0}">  
            太惨了  
        </c:when>  
        <c:when test="${salary > 0 && salary <= 2000}">  
            一般般  
        </c:when>  
        <c:when test="${salary > 2000 && salary <= 4000}">  
            还不错  
        </c:when>  
        <c:otherwise>  
            太棒了  
        </c:otherwise>  
    </c:choose>  
</p>  
  
<c:import var="data" url="index.jsp"/>  
<c:out value="${data}"/>  
${data}  
  
<c:forEach items="${items}" var="item" varStatus="itemStatus">  
    ${itemStatus.index}:${item}  <br>  
</c:forEach>  
<hr>  
<c:forTokens items="${tokenItems}" delims="," var="item" varStatus="itemStatus">  
    ${itemStatus.index}:${item}  <br>  
</c:forTokens>  
  
<c:redirect url="https://www.baidu.com"/>  
</body>  
</html>

评论