struts2 标签 和 c标签的页面数据显示

时间:2023-01-10 19:38:21

用struts2 标签显示的页面代码

<s:if test="#request.employees == null || #request.employees.size() == 0">
  没有任何员工信息
</s:if>
<s:else>
  <table border="1" cellpadding="10" cellspacing="0">
    <tr>
      <td>ID</td>
      <td>LASTNAME</td>
      <td>EMAIL</td>
      <td>BIRTH</td>
      <td>CREATETIME</td>
      <td>DEPT</td>
      <td>DELETE</td>
      <td>EDIT</td>
    </tr>
  <s:iterator value="#request.employees">
    <tr>
      <td>${id }</td>
      <td>${lastName }</td>
      <td>${email }</td>
      <td>
        <s:date name="birth" format="yyyy-MM-dd"/>
      </td>
      <td>
        <s:date name="createTime" format="yyyy-MM-dd hh:mm:ss"/>
      </td>
      <td>${department.departmentName }</td>
      <td>
        <a href="ajax/delete?id=${id}">Delete</a>
      </td>
      <td>
        <a href="emp-add?id=${id}">Edit</a>
      </td>
    </tr>
    </s:iterator>
  </table>
</s:else>

用jsp c标签显示的页面代码

<c:if test="${empty requestScope.employees}">
  没有员工信息!
</c:if>
<c:if test="${!empty requestScope.employees}">
  <table border="1" cellpadding="10" cellspacing="0">
    <tr>
      <td>ID</td>
      <td>LastName</td>
      <td>Gender</td>
      <td>Department</td>
      <td>Edit</td>
      <td>Delete</td>
    </tr>
<c:forEach items="${requestScope.employees}" var="emp">
    <tr>
      <td>${emp.id}</td>
      <td>${emp.lastName}</td>
      <td>${emp.gender == 0? '女':'男'}</td>
      <td>${emp.department.departmentName}</td>
      <td><a href="">Edit</a></td>
      <td><a href="">Delete</a></td>
    </tr>
</c:forEach>
</table>
</c:if>