【问题标题】:I want to add jstl C:if tag in my code in a form but not able to understand how to implement it [duplicate]我想以表单的形式在我的代码中添加 jstl C:if 标记,但无法理解如何实现它[重复]
【发布时间】:2016-07-01 20:25:34
【问题描述】:
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>

【问题讨论】:

    标签: forms jsp jstl


    【解决方案1】:

    来自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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 2020-12-24
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多