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>
答案 0 :(得分:0)
来自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>