导入标签库:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<body>
<p> <input type = "hidden" id = "add" value="新增" />
<c:if test="${power == 'delete' }">
<input type = "button" id = "deleteAll" value="批量删除" />
</c:if>
</p>
<p>
<form action="ToBookListServlet.do" method="post">
书名:<input type = "text" id = "qbookName" name="qbookName" value="${pageBean.query.qbookName }" >
图书类型:<select id="qtypeId" name="qtypeId">
<option value="0" selected="selected" >--全部--</option>
<c:forEach var="type" items="${typeList }">
<option value="${type.typeId }" <c:if test="${type.typeId == pageBean.query.qtypeId }">selected="selected"</c:if>>${type.typeName }</option>
</c:forEach>
</select>
jstl格式化日期:
出版日期区间:从<input type = "date" id = "startDate" name="startDate" value="<fmt:formatDate value='${pageBean.query.startDate }' pattern='yyyy-MM-dd'/>" />
到<input type = "date" id = "endDate" name="endDate" value="<fmt:formatDate value='${pageBean.query.endDate }' pattern='yyyy-MM-dd'/>"/>
<input type = "submit" value="查询" />
</form>
</p>
<table id = "bookList">
<tr>
<c:if test="${power =='delete' }">
<td><input type="checkbox" name="selectAll" onclick="selectAll(this)"/>全选</td>
</c:if>
<td>编号</td>
<td>书名</td>
<td>类型</td>
<td>作者</td>
<td>出版社</td>
<td>出版日期</td>
<td>库存</td>
<c:if test="${power =='delete' or power == 'modify'}">
<td>操作</td>
</c:if>
</tr>
<c:forEach var="book" items="${bookList }">
<tr>
<c:if test="${power =='delete' }">
<td><input type="checkbox" name="cbox" value="${book.bookId }" /></td>
</c:if>
<td>${book.bookId }</td>
<td>${book.bookName }</td>
<td>${book.bookType.typeName }</td>
<td>${book.author }</td>
<td>${book.publish }</td>
<td><fmt:formatDate value="${book.pubDate }" pattern="yyyy-MM-dd"/></td>
<td>${book.stock }</td>
<c:if test="${power =='delete' }">
<td>
<input type="button" name="del_btn" value="删除" onclick="deleteBook('${book.bookId }')"/>
</td>
</c:if>
<c:if test="${power =='modify' }">
<td>
<input type="button" name="mod_btn" value="修改" onclick="modify('${book.bookId }')"/>
</td>
</c:if>
</tr>
</c:forEach>
</table>
动态拼接url:
<!-- 拼接url -->
<c:url var="carUrl" value="ToBookListServlet.do">
<c:param name="qbookName" value="${pageBean.query.qbookName }"></c:param>
<c:param name="qtypeId" value="${pageBean.query.qtypeId }"></c:param>
param的value:
<c:param name="startDate" >
<fmt:formatDate value="${pageBean.query.startDate }" pattern="yyyy-MM-dd"/>
</c:param>
<c:param name="endDate" >
<fmt:formatDate value="${pageBean.query.endDate }" pattern="yyyy-MM-dd"/>
</c:param>
<c:if test="${power =='delete' }">
<c:param name="power" value="delete"></c:param>
</c:if>
<c:if test="${power =='modify' }">
<c:param name="power" value="modify"></c:param>
</c:if>
</c:url>
<p>
jstl的多分支:choose
<c:choose>
<c:when test="${pageBean.totalPage != 0}">
<a href="${carUrl }&page=1">首页</a>
<c:choose>
<c:when test='${pageBean.page!=1 }'><a href="${carUrl }&page=${pageBean.page - 1}">上一页</a></c:when>
<c:otherwise><a>上一页</a> </c:otherwise>
</c:choose>
<c:choose>
<c:when test='${pageBean.page < pageBean.totalPage }'><a href="${carUrl }&page=${pageBean.page + 1}">下一页</a></c:when>
<c:otherwise><a>下一页</a> </c:otherwise>
</c:choose>
<a href="${carUrl }&page=${pageBean.totalPage}">尾页</a>
<span id="pager">${pageBean.page } / ${pageBean.totalPage}</span>
</c:when>
<c:otherwise>
暂无数据
</c:otherwise>
</c:choose>
</p>
</body>