根据如下的一个foreach遍历例子说明:
${fileList } 接收到的值如下红色所示:
[{filename=梁宽.jpg, suffix=.jpg, url=im/groupnotice/downloadFile.action?url=e31b0484-12bf-438d-a8a2-6fbf1a720816.jpg&filename=梁宽.jpg}
,
{filename=测试.txt, suffix=.txt, url=im/groupnotice/downloadFile.action?url=402242c7-9146-4bc7-9130-f4f18dbd6257.txt&filename=测试.txt}]
<c:forEach items="${fileList }" var="items">
<c:if test="${items.suffix=='.jpg' }">
<a href="${items.url}">
<i class="fa fa-picture-o"></i>
<span class="rt-green">${items.filename}</span>
</a>
</c:if>
<c:if test="${items.suffix=='.txt' }">
<a href="${items.url}">
<i class="fa fa-file-text"></i>
<span class="rt-green">${items.filename}</span>
</a>
</c:if>
<c:if test="${items.suffix != '.jpg' && (items.suffix != '.txt')}">
<a href="${items.url}">
<i class="fa fa-file"></i>
<span class="rt-green">${items.filename}</span>
</a>
</c:if>
</c:forEach>
我现在想用<c:if>标签来做一个判断
(1)如果${items.suffix}即为.jpg、.txt等文件的后缀名 == '.jpg'时,展示为图片的展示
,此种写法为:
<c:if test="${items.suffix=='.jpg' }">
图片图标。
</c:if>
(2)如果${items.suffix}即为.jpg、.txt等文件的后缀名 == '.txt'时,展示为文本的展示
,此种写法为:
<c:if test="${items.suffix=='.txt' }">
文本图标。
</c:if>
(3)如果${items.suffix}即为.jpg、.txt等文件的后缀名 为其它的图标时,展示为其它图标的展示
,此种写法为:
<c:if test="${items.suffix != '.jpg' && (items.suffix != '.txt')}">
其它图标。
</c:if>
因为jsp里面没有c : else标签,所以可以用上面的替代,上面三种情况覆盖了所有,需要的再添加进去就好了,有需要的互相讨论学习。