我想在我的代码中添加 jstl C:if 标签的形式,但无法理解如何实现它


Hello i want to add JSTL C:if tag in a form but did not able to understand how to implement it .
i have a file for attractions where i want to add the c:if tag in it the task i want to carry out is whenever i am navigating from other page to this present page if there are no datas available from database it should show " no datas available please add new data "
 the code for for the form is as follows 

这是我必须添加 c:if 标签的代码,它解释说,因为它显示了从城市页面导航的数据库中的景点列表及其 ID 我想要输出,就好像我从城市导航到景点页面一样,如果其中没有景点,我应该收到消息为"没有可用数据,请添加新数据"

<div class="row">
            <div id="attractionList" class="col-sm-12">
                <h3 >
                    Attractions
                </h3>

                <c:forEach items="${attraction}" var="a">
                    <div id="attractionTable" class="col-sm-3">
                        <form action="/RouternData/roternInternal" method="post">
                            <input type="hidden" value="YES" name="DELETEATTRACTION">
                                <input type="hidden" value="${a.cityid }" name="cityid">

                            <div class="box7">
                                <div>
                                <img alt="image1" src="jspfiles/image/vadodara-palace1.jpg"
                                        width="100%" height="100px">
                                </div>
                                <div>

                                    <br> <a
                                        href='/RouternData/roternInternal?RETRIVEATTRACTIONDATA=YES&attractionId=${a.attractionId}'
                                        onclick ="showAttractions()" name="attractionname">${a.attraction }</a><br>

                                    <b>Day ;</b> <i> ${a.days }</i><br>
                                     <b>Type of attraction :</b> <i>${a.type}</i><br>
                                     <button type="submit" style="color: #990000" class="btn btn-link" value="${a.attractionId}"
                                            name="attractionId">Delete</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <%-- <h3>${a.attraction }</h3>--%>

                </c:forEach>
            </div>
        </div>

来自 JSTL1.1

length( java.lang.Object)

返回集合中的项数或字符串中的字符数。

在页面开头应用以下代码以使用fn命名空间

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

假设${attraction}Java Collection对象,您可以使用c:choose来决定如果${attraction}为空该怎么办

<c:choose>
    <c:when test="${fn:length(attraction) gt 0}">
        <!-- attraction is not empty -->
    </c:when>
    <c:otherwise>
        <!-- attraction is empty -->
    </c:otherwise>
</c:choose>

最新更新