html表使用jstl标签打印错误

时间:2019-01-19 11:42:10

标签: html

我正在建立一个在线电影院预订系统,在页面上我应该看到一张座位表。如果预订了座位,它必须是红色的,所以我做的座位表 'c:forEach'循环,在$ {listTickets}中,我有4张预订的票(7、12、14、19),所以预订了'tk.seat',我希望它正确输出20个席位,其中4个应该是红色,但是我认为问题在foreach循环中,它输出4次,我有这个...

有人知道为什么会这样吗?

代码

<table class="table">

    <thead>
    <tr>
        <td></td>
        <c:forEach begin="1" end="5" varStatus="loop">
            <td>${loop.index}</td>
        </c:forEach>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <c:forEach begin="1" end="5" varStatus="loop">

            <c:forEach var="tk" items="${listTickets}">
                <c:choose>
                    <c:when test="${tk.seat==loop.index}">
                        <td style="background-color:red;">${loop.index}</td>
                    </c:when>
                    <c:otherwise>
                        <td>${loop.index}</td>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
        </c:forEach>
    </tr>
    <tr>
        <td>2</td>
        <c:forEach begin="6" end="10" varStatus="loop">

            <c:forEach var="tk" items="${listTickets}">
                <c:choose>

                    <c:when test="${tk.seat==loop.index}">
                        <td style="background-color:red;">${loop.index}</td>
                    </c:when>
                    <c:otherwise>
                        <td>${loop.index}</td>
                    </c:otherwise>

                </c:choose>
            </c:forEach>

        </c:forEach>

    </tr>
    <tr>
        <td>3</td>
        <c:forEach begin="11" end="15" varStatus="loop">

            <c:forEach var="tk" items="${listTickets}">
                <c:choose>

                    <c:when test="${tk.seat==loop.index}">
                        <td style="background-color:red;">${loop.index}</td>
                    </c:when>
                    <c:otherwise>
                        <td>${loop.index}</td>
                    </c:otherwise>

                </c:choose>
            </c:forEach>

        </c:forEach>
    </tr>
    <tr>
        <td>4</td>
        <c:forEach begin="16" end="20" varStatus="loop">

            <c:forEach var="tk" items="${listTickets}">
                <c:choose>

                    <c:when test="${tk.seat==loop.index}">
                        <td style="background-color:red;">${loop.index}</td>
                    </c:when>
                    <c:otherwise>
                        <td>${loop.index}</td>
                    </c:otherwise>

                </c:choose>
            </c:forEach>

        </c:forEach>
    </tr>
    </tbody>
</table>

enter image description here

0 个答案:

没有答案