jsp自定义标签if,ifelse,for的实现

if语句的实现:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>c:if标签实例</title>
        <%
            int a=8;
            request.setAttribute("aa", a);
        %>
        <c:if test="${aa>6}">
            a>6
        </c:if>
    </head>
    <body>
    </body>
</html>

ifelse语句的实现:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ifelse标签实例</title>
    </head>
    <body>
        <%
            int a=7;
            request.setAttribute("aa", a);
        %>
        <c:choose>
            <c:when test="${aa<5 }">a<5</c:when>
            <c:otherwise>a>5</c:otherwise>
        </c:choose>
    </body>
</html>

for语句的实现:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>for标签实例</title>
    </head>
    <body>
        <c:forEach var="i" begin="0" end="4">
            ${i }<br>
        </c:forEach>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_41815326/article/details/81356733