首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想在我的代码中以表单的形式添加jstl C:if标记,但不能理解如何实现它

我想在我的代码中以表单的形式添加jstl C:if标记,但不能理解如何实现它
EN

Stack Overflow用户
提问于 2016-03-16 13:35:25
回答 1查看 552关注 0票数 0
代码语言:javascript
复制
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,该列表是从排序中的城市页面导航的。我希望输出结果就像我从城市导航到景点页面一样,如果其中没有景点,我应该会收到消息“没有可用的数据,请添加新数据”。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2016-03-16 15:29:09

来自JSTL1.1

代码语言:javascript
复制
length( java.lang.Object)

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

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

代码语言:javascript
复制
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

假设${attraction}是一个Java Collection对象,您可以使用c:choose来决定如果${attraction}为空时该如何处理

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36027515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档