San*_*one 9 java jsp if-statement jstl
我有这条线
<td><c:out value="${row.file_name}"/></td>
Run Code Online (Sandbox Code Playgroud)
file_name是mysql数据库表中的列名.我想检查file_name是否有一些值,所以我想使用IF condition,但是如何通过row.file_name?就像是if(row.file_name!=null){}
UPDATE
<td><c:out value="${row.file_name}"/><br>
<c:choose>
<c:when test="${row.file_name == null}">
Null
</c:when>
<c:otherwise>
<a href="downloadFileServlet?id=${row.id}">Download</a></td>
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,即使file_name为空,也只执行第二个条件
首先,if不是循环,它只是一个声明.您可以使用<c:if>标记来测试值:
<c:if test="${row.file_name != null}">
Not Null
</c:if>
Run Code Online (Sandbox Code Playgroud)
而对于Java if-else语句,JSTL标记等价于<c:choose>(不,没有<c:else>):
<c:choose>
<c:when test="${row.file_name != null}">
Not Null
</c:when>
<c:otherwise>
Null
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)
请注意,${row.file_name != null}条件true仅适用于non-null文件名.并且空文件名不为空.如果要检查两者null和空文件名,则应使用empty条件:
<!-- If row.file_name is neither empty nor null -->
<c:when test="${!empty row.file_name}">
Not empty
</c:when>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37596 次 |
| 最近记录: |