分页显示问题,向高手请教!!

xxbb 2004-09-02 10:48:17
<html>
<body bgcolor="#ffdee">
<table width="146" >
<tr><td bgcolor="#CCCC99"><center>程序设计</center></a></td></tr>
<td bgcolor="#C0C0C0">
<a href="/shop/result.jsp?pro=java" target="_top">java</a>       
<a href="/shop/result.jsp?pro=.net" target="_top">.net</a>
<a href="/shop/result.jsp?pro=Delphi" target="_top">Delphi</a>      
<a href="/shop/result.jsp?pro=C++" target="_top">C++</a></td>
<tr><td bgcolor="#CCCC99"><center>数据库</center></a></td></tr>
<td bgcolor="#C0C0C0">
<a href="/shop/result.jsp?pro=Oracle" target="_top">Oracle</a>     
<a href="/shop/result.jsp?pro=mysql" target="_top">Mysql</a>
<a href="/shop/result.jsp?pro=Sqlserver" target="_top">Sqlserver</a>
<tr><td bgcolor="#CCCC99"><center>操作系统及其它</center></a></td></tr>
<td bgcolor="#C0C0C0">
<a href="/shop/result.jsp?pro=Linux" target="_top">Linux</a>   
<a href="/shop/result.jsp?pro=Windows" target="_top">Windows</a><br>
<a href="/shop/result.jsp?pro=网络" target="_top">网络</a>    
<a href="/shop/result.jsp?pro=图形图像" target="_top">图形图像</a></td>
</table>
</body>
</html>


<%@ page contentType="text/html; charset=GBK" import="javax.naming.*,javax.sql.*,java.sql.*, java.util.*, javax.ejb.*, javax.rmi.PortableRemoteObject, register.*" %>
<%@ page errorPage="error.jsp" %>
<%@ include file="trans.jsp"%>
<html>
<head>
<title>
searchbookByCategory
</title>
</head>
<body bgcolor="#ffffff">
<center>
<table width="770" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center"><%@ include file="/title.jsp"%>
</td>
</tr>
<tr>
<td align="center"><%@ include file="/search2.jsp"%>
</td>
</tr>
</table>
<%
int MaxPage;//总页数
int maxRow;//总行数
int pageSize =3;//一页显示3行
int intPage;//第几页

String category = request.getParameter("pro");
String num = request.getParameter("Page");
if(num!=null){
intPage=Integer.parseInt(num);
}else{
intPage=1;
}

try
{
Context ctx = new InitialContext();
facadeHome fhome = (facadeHome)PortableRemoteObject.narrow(ctx.lookup("facade"), facadeHome.class);
facade f = fhome.create();
Collection c = f.getBooksByCategory(category);
maxRow = c.size();
if( maxRow % pageSize == 0 )
{
MaxPage = maxRow / pageSize;
}
else
{
MaxPage = maxRow / pageSize + 1;
}
Iterator it = c.iterator();
%><table width=70%><%
if( MaxPage > 0){ int a = 0;
while(a<pageSize){
Book temp = (Book)it.next();
String bookid = temp.getBookid();
%>

<tr><td rowspan="4"><img src=<%=temp.getPicture()%>></td>
<td>书名:<a href="viewbook.jsp?bookid=<%=temp.getBookid()%>"><%=trans(temp.getName())%></a></td></tr>
<tr><td>作者:<%=trans(temp.getAuthor())%></td><td>译者:<%=trans(temp.getTranslator())%></td></tr>
<tr><td>价格:<%=temp.getPrice()%></td><td>会员价格:<%=temp.getMemberprice()%></td></tr>
<tr><td>出版社:<%=trans(temp.getPublisher())%></td>
<% int i = temp.getStock();
if(i>0){%>
<td><a href="<%=request.getContextPath()%>/showcart.jsp?Addbook=<%=bookid%>">加入购物车</a></td></tr>
<%}else{%>
<td><a href="noughtbook.jsp">加入购物车</a>  <font color="red">缺货</font></td></tr>
<%} //end of if
a++;
}%>
</table>
</center>
</body>
第<%=intPage%>页 共<%=MaxPage%>页
<%if(intPage>1){%><a href="result.jsp?Page=<%=intPage-1%>">上一页</a><%}%>
<%if(intPage<MaxPage){%><a href="result.jsp?Page=<%=intPage+1%>">下一页</a><%}%>
<%}}catch(Exception e)
{e.printStackTrace();}
%>
</html>



package register;

import javax.ejb.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;
import java.sql.*;

public class facadeBean
implements SessionBean
{
SessionContext sessionContext;
private DataSource ds = null;
private BooksHome bhome = null;
private Books books = null;
private UserinfoHome uhome = null;
private Userinfo userinfo = null;
private OrdersHome ohome = null;
private Orders orders = null;
private LineitemHome lhome = null;
private Lineitem lineitem = null;
String orderid = null;

public void ejbCreate() throws CreateException
{
/**@todo Complete this method*/
try
{
Context ctx = new InitialContext();
Object obj = ctx.lookup( "java:/comp/env/bookitem" );
bhome = ( BooksHome )obj;
obj = ctx.lookup( "java:/comp/env/users" );
uhome = ( UserinfoHome )obj;
obj = ctx.lookup( "java:/comp/env/order" );
ohome = ( OrdersHome )obj;
obj = ctx.lookup( "java:/comp/env/lineitem" );
lhome = ( LineitemHome )obj;
}
catch( Exception e )
{
e.printStackTrace();
}

}

public void ejbRemove()
{
/**@todo Complete this method*/
}

public void ejbActivate()
{
/**@todo Complete this method*/
try
{
Context ctx = new InitialContext();
Object obj = ctx.lookup( "java:/comp/env/bookitem" );
bhome = ( BooksHome )obj;
obj = ctx.lookup( "java:/comp/env/users" );
uhome = ( UserinfoHome )obj;
obj = ctx.lookup( "java:/comp/env/order" );
ohome = ( OrdersHome )obj;
obj = ctx.lookup( "java:/comp/env/lineitem" );
lhome = ( LineitemHome )obj;

}
catch( Exception e )
{
e.printStackTrace();
}

}

public void ejbPassivate()
{
/**@todo Complete this method*/
bhome = null;
uhome = null;
ohome = null;
lhome = null;
}

public void setSessionContext( SessionContext sessionContext )
{
this.sessionContext = sessionContext;
}

//按类型查询书籍
public java.util.Collection getBooksByCategory( String category )
{
/**@todo Complete this method*/
Collection result = new ArrayList();
try
{
Collection c = bhome.findByCategory( category );
Iterator i = c.iterator();
while( i.hasNext() )
{
books = ( Books )i.next();
Book book = new Book();
book.setBookid( books.getBookid() );
book.setName( books.getName() );
book.setAuthor( books.getAuthor() );
book.setTranslator( books.getTranslator() );
book.setPrice( books.getPrice() );
book.setMemberprice( books.getMemberprice() );
book.setPublisher( books.getPublisher() );
book.setStock( books.getStock() );
book.setCategory( books.getCategory() );
book.setPicture( books.getPicture() );
book.setDescription( books.getDescription() );

result.add( book );
}
}
catch( Exception e )
{
e.printStackTrace();
}
return result;

}
}

为什么我点“下一页”后,屏幕上面什么也没有啊!
...全文
146 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xxbb 2004-09-06
可是我的数据是通过EJB-QL语言查询出来的,都放在ArrayList里面!我如何才能把ArrayList里面的数据分页显示呢?
回复
xiaowenand 2004-09-06
在执行查询数据库后要rs.last();
回复
xxbb 2004-09-04
怎么没有人回答我啊!
回复
weepp 2004-09-02
没传值啊!好好看看!
回复
xxbb 2004-09-02
<%@ page contentType="text/html; charset=GBK" import="javax.naming.*,javax.sql.*,java.sql.*, java.util.*, javax.ejb.*, javax.rmi.PortableRemoteObject, register.*" %>
<%@ page errorPage="error.jsp" %>
<%@ include file="trans.jsp"%>
<html>
<head>
<title>
searchbookByCategory
</title>
</head>
<body bgcolor="#ffffff">
<center>
<table width="770" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center"><%@ include file="/title.jsp"%>
</td>
</tr>
<tr>
<td align="center"><%@ include file="/search2.jsp"%>
</td>
</tr>
</table>
<%
int MaxPage;//总页数
int maxRow;//总行数
int pageSize =3;//一页显示3行
int intPage;//第几页

String category = request.getParameter("pro");
String num = request.getParameter("Page");
if(num!=null){
intPage=Integer.parseInt(num);
}else{
intPage=1;
}

try
{
Context ctx = new InitialContext();
facadeHome fhome = (facadeHome)PortableRemoteObject.narrow(ctx.lookup("facade"), facadeHome.class);
facade f = fhome.create();
Collection c = f.getBooksByCategory(category);
maxRow = c.size();
if( maxRow % pageSize == 0 )
{
MaxPage = maxRow / pageSize;
}
else
{
MaxPage = maxRow / pageSize + 1;
}
Iterator it = c.iterator();
%><table width=70%><%
if( MaxPage > 0){ int a = 0;
while(a<pageSize){
Book temp = (Book)it.next();
String bookid = temp.getBookid();
%>

<tr><td rowspan="4"><img src=<%=temp.getPicture()%>></td>
<td>书名:<a href="viewbook.jsp?bookid=<%=temp.getBookid()%>"><%=trans(temp.getName())%></a></td></tr>
<tr><td>作者:<%=trans(temp.getAuthor())%></td><td>译者:<%=trans(temp.getTranslator())%></td></tr>
<tr><td>价格:<%=temp.getPrice()%></td><td>会员价格:<%=temp.getMemberprice()%></td></tr>
<tr><td>出版社:<%=trans(temp.getPublisher())%></td>
<% int i = temp.getStock();
if(i>0){%>
<td><a href="<%=request.getContextPath()%>/showcart.jsp?Addbook=<%=bookid%>">加入购物车</a></td></tr>
<%}else{%>
<td><a href="noughtbook.jsp">加入购物车</a>  <font color="red">缺货</font></td></tr>
<%} //end of if
a++;
}%>
</table>
</center>
</body>
第<%=intPage%>页 共<%=MaxPage%>页
<%if(intPage>1){%><a href="result.jsp?Page=<%=intPage-1%>">上一页</a><%}%>
<%if(intPage<MaxPage){%><a href="result.jsp?Page=<%=intPage+1%>">下一页</a><%}%>
<%}}catch(Exception e)
{e.printStackTrace();}
%>
</html>
回复
cocohui 2004-09-02
这么多我看都看不到。。什么东东啊 。。下次不要什么都发。。重要的就是了。。
回复
xxbb 2004-09-02
那里啊!!你快告诉我啊!我把分都给你!!
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-02 10:48
社区公告
暂无公告