博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在JSP使用EL和JSTL判断指定元素是否存在于指定集合中
阅读量:2386 次
发布时间:2019-05-10

本文共 1240 字,大约阅读时间需要 4 分钟。

判断某一元素是否在一个集合中

<!-- set集合,存储测试值存在于集合否? -->

<c:set var="iscontain" value="false" />
<!-- 原始集合:items,集合元素 :var-->
<c:forEach items="${collection}" var="element">
<!-- 判断测试值是否存在于集合中,存在将iscontain置为true -->
<c:if test="${element eq 4}">
<c:set var="iscontain" value="true" />
</c:if>
</c:forEach>
<!-- 测试值在集合中 -->
<c:if test="${iscontain}">如果指定元素在指定集合中执行的代码</c:if>
<!-- 测试值不在集合中 -->

<c:if test="${!iscontain}">如果指定元素不在指定集合中执行的代码</c:if>

JSTL标签
用于保存数据

与我们在一般程序中用的if一样

基础迭代标签,接受多种集合类型

用到项目中,select标签,显示合作单位信息已被选择,其他单位信息显示不出现重复

<!-- 显示当前草稿合作单位信息 -->

<c:if test="${not empty cooDepts }">

<select id="sel" name="cooDeparts"  multiple="multiple" style="width:100px">

<c:forEach var="department" items="${departments}">

<c:set var="iscontain" value="false"></c:set>

<c:forEach var="cooDept" items="${cooDepts}">

<c:if test="${department.deptId ==  cooDept.deptId}">

<option value="${department.deptId}" selected="selected">${department.deptName}</option>

<c:set var="iscontain" value="true"></c:set>

</c:if>

</c:forEach>

<c:if test="${!iscontain }"><option value="${department.deptId}">${department.deptName}</option></c:if>

</c:forEach>

</select>

</c:if>

参考地址

http://www.cnblogs.com/zfc-java/p/6862224.html

http://www.cnblogs.com/tingbogiu/p/5829010.html

你可能感兴趣的文章
Security Ressources Sites
查看>>
mysql的比较运算
查看>>
Data Breach Report
查看>>
再探偏移注射
查看>>
DNS Security Tips
查看>>
符号执行
查看>>
Remote Installation Service (RIS) in Windows Server 2003
查看>>
Layer Four Traceroute
查看>>
Hardening guide for Apache 2.2.15 on RedHat 5.4 (64bit edition)
查看>>
Microsoft Outlook Web Access (OWA) version 8.2.254.0 information disclosure vulnerability
查看>>
STP mitm attack idea
查看>>
Month of PHP Security - Summary
查看>>
近期将要购买的图书
查看>>
nginx Directory Traversal Vulnerability
查看>>
Linux下apache+svn+ssl完美结合搭建安全版本控制平台
查看>>
Nginx 0.8.35 Space Character Remote Source Disclosure
查看>>
showrun的cissp经验谈
查看>>
6月4日要买的书
查看>>
nginx Remote Source Code Disclosure and Denial of Service Vulnerabilities
查看>>
Anti-sec安全培训 部分试看视频
查看>>