我有一个table.jsp文件,我从后端获取一些数据。表中的一个字段是状态。在状态中,我得到两个数字,如" 1"和" 0"。但我想展示" 1"意味着"活跃" " 0"意味着"不活跃"。请帮我解决这些问题。下面是我的代码:
/。table.jsp
<div class="row">
<div class="col-lg-12">
<div class="panel panel-success">
<div class="panel-heading">User Online
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered display" cellspacing="0" width="100%">
<thead style="font-size:11px;">
<tr>
<th>S.No</th>
<th>Name</th>
<th>Usn Number</th>
<th>Mobile Number</th>
<th>Email ID</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<c:forEach var="UserList" varStatus="status" items="${UserList}">
<tr>
<td><c:out value="${status.index+1}"/></td>
<td><c:out value="${UserList.name}"/></td>
<td><c:out value="${UserList.usn}"/></td>
<td><c:out value="${UserList.mobile}"/></td>
<td><c:out value="${UserList.email}"/></td>
<td><c:out value="${UserList.Status}"/></td> <!-- currently UserList.Status = "1"/"0" is printing, if "1" show "active" if "0" show "inactive" -->
</tr>
</c:forEach>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
答案 0 :(得分:0)
也许jstl标签可以解决这个问题,如下所示:
<c:if test = "${userListList.status == 1}">
active
</c:if>
<c:if test = "${userListList.status == 0}">
deactivate
</c:if>
并在文件开头写下这个导入句子:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
答案 1 :(得分:0)
您可以使用
<c:when>
标签。例如,
<c:when>
<c:choose test="${UserList.Status == 1}">
<td>Active</td>
</c:choose>
<c:otherwise>
<td> Inactive</td>
</c:otherwise>
</c:when>
答案 2 :(得分:0)
<div class="row">
<div class="col-lg-12">
<div class="panel panel-success">
<div class="panel-heading">User Online
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered display" cellspacing="0" width="100%">
<thead style="font-size:11px;">
<tr>
<th>S.No</th>
<th>Name</th>
<th>Usn Number</th>
<th>Mobile Number</th>
<th>Email ID</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<c:forEach var="UserList" varStatus="status" items="${UserList}">
<tr>
<td><c:out value="${status.index+1}"/></td>
<td><c:out value="${UserList.name}"/></td>
<td><c:out value="${UserList.usn}"/></td>
<td><c:out value="${UserList.mobile}"/></td>
<td><c:out value="${UserList.email}"/></td>
<c:if test = "${UserList.Status == 1}">
<td>active</td>
</c:if>
<c:if test = "${UserList.Status == 0}">
<td>inactive</td>
</c:if>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
我希望它对你有用。