<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<script language="JavaScript">
function getvalue(){
form1.my1.value='0'
form1.isbn.value=event.srcElement.value
form1.qua.value=1
}
function getvalue1(){
form1.my1.value='1'
form1.isbn.value=event.srcElement.value
form1.qua.value=1;
}
</script>
<title>jsp2 </title>
</head>
<BODY >
<c:choose>
<c:when test='${empty param.scroll1}'>
<sql:query var='lookbyname' dataSource="${sqlDataSource}">
select a.isbn ,a.bname,b.path, c.aname,a.outprice,a.outprice*a.zhekou xianjia , d.pressname ,a.pdate from mybook a,picture b ,authors c,press d where a.isbn=b.pid(+) and a.aid=c.aid(+) and a.pressid=d.pressid(+) and a.typeid is not null and a.bname like ?
<sql:param value='%${param.bkname}%' />
</sql:query>
<c:set var='scrollMax1' value='${lookbyname.rowCount}' scope='session' />
<c:set var='scrollStart1' value='0' scope='session' />
<c:set var='bname' value='${param.bkname}' scope='session' />
</c:when>
<c:when test='${param.scroll1 == "forward"}'>
<c:if test='${scrollStart1 + 5< scrollMax1}'>
<c:set var='scrollStart1' value='${scrollStart1 + 5}' scope='session' />
</c:if>
</c:when>
<c:when test='${param.scroll1 == "backward"}'>
<c:if test='${scrollStart1 - 5 >= 0}'>
<c:set var='scrollStart1' value='${scrollStart1 - 5}' scope='session' />
</c:if>
</c:when>
</c:choose>
<sql:query var='lookbyname' startRow='${scrollStart1}' maxRows='5' dataSource="${sqlDataSource}">
select a.isbn ,a.bname,b.path, c.aname,a.outprice,a.outprice*a.zhekou xianjia , d.pressname ,a.pdate from mybook a,picture b ,authors c,press d where a.isbn=b.pid(+) and a.aid=c.aid(+) and a.pressid=d.pressid(+) and a.typeid is not null and a.bname like ?
<sql:param value='%${bname}%' />
</sql:query>
<c:out value="${param.bkname}"/>
共找到<c:out value='${scrollMax1}' />本书
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="666" border="0" height="36">
<TR>
<TD>
<font face="宋体" size="4">
<P align="center"><a href='jsp1.jsp?scroll1=forward'>前一页</a> <a href='jsp1.jsp?scroll1=backward'>后一页</a></P>
</font>
</TD>
</TR>
</TABLE>
<Form name="form1" action="jupe.jsp" ID="Form1">
<input type="hidden" name="qua"/>
<input type="hidden" name="my1" ID="Hidden1" /> <input type="hidden" name="isbn" ID="Hidden2" />
<c:forEach var='row1' items='${lookbyname.rows}'>
<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="666" border="0" height="111" bgcolor="#ffccff">
<TR>
<TD vAlign="top" bgcolor="#ffcc33"><P>
<c:choose>
<c:when test='${not empty row1.path}'>
<input type="image" οnclick="getvalue()" value="<c:out value='${row1.isbn}'/>" src="<c:out value='${row1.path}'/>" width="102" align="right" ID="Image1" NAME="Image1">
</c:when>
<c:when test='${empty row1.path }'>
<input type="image" οnclick="getvalue()" value="<c:out value='${row1.isbn}'/>" height="138" alt=" " src="images/no_pic.jpg" width="102" align="right" ID="Image2" NAME="Image2">
</c:when>
</c:choose>
<FONT size="3"> <FONT color="#009933">书名 :<c:out value="${row1.bname}" /><BR>
作者 :<c:out value="${row1.aname}" />
出版社:<c:out value="${row1.pressname}" /><BR>
日 期:<c:out value="${row1.pdate}" /></FONT></FONT></P>
<P><FONT size="3"> <FONT color="#009933">定 价:<c:out value="${row1.outprice}" />元 优惠价:<c:out value="${row1.xianjia}" />元</FONT></FONT>
<input type="image" οnclick="getvalue1()" height="33" alt="" src="images/gwc.gif" width="91" value="<c:out value='${row1.isbn}'/>" ID="Image3" NAME="Image3"><BR>
</P>
</TD>
</TR>
<hr width="100%" size="1">
</TABLE>
</c:forEach>
</Form>
<TABLE id="Table3" cellSpacing="1" cellPadding="1" width="666" border="0" height="36">
<TR>
<TD>
<font face="宋体" size="4">
<P align="center"><a href=' jsp1.jsp?scroll1=forward'>前一页</a> <a href='jsp1.jsp?scroll1=backward'>后一页</a></P>
</font>
</TD>
</TR>
</TABLE>
<br>
</BODY>
</html>
这个分页是我刚学用JSTL时写的所以布局很乱也不是很规范。
我现在觉得JSTL做分页还有一个缺点。就是很对保证没有非法字符。听说可以在jstl1.2中可以克服, 因为多了一个fn的taglib 。但是还是觉得这个结构不够完美。