<%@ page language="java" contentType="text/html; charset=utf-8"
import="dao.*,java.util.*,entity.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<title>商品展示</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link stype=>
<title>Insert title here</title>
</head>
<%
request.setCharacterEncoding("utf-8");
//捕获数据
int currentpage = 1;
int pagesize = 5;
String parampage = request.getParameter("page"); if (parampage != null) {
currentpage = Integer.parseInt(parampage);
}
//处理数据
ProductDao productDao = new ProductDao();
List productList = productDao.getProductList(currentpage, pagesize);
List allProductList = productDao.findAllProduct();
%>
<script type="text/javascript">
function openChat() { window.open("<%=request.getContextPath()%>/chat/index.jsp", "",
"left=250   top=200   width=500   height=400");
}
</script><link href="<%=request.getContextPath()%>/css/right.css" rel="stylesheet" type="text/css" /><BODY leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<%@ include file="../top.jsp" %>
<TABLE height=28 cellSpacing=3 cellPadding=0 width=776 align=center
border=0>
<TBODY>
<TR vAlign=bottom>
<TD>&nbsp;&nbsp; <A class=nav href="<%=request.getContextPath()%>/index.jsp">首页</A><FONT
class=nav> &gt; </FONT><A class=nav href="<%=request.getContextPath()%>/product/showProductList.jsp">商品展示</A>
</TD>
</TR>
</TBODY>
</TABLE>
<TABLE height=1 cellSpacing=0 cellPadding=0 width=776 align=center
bgColor=#cccccc border=0>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=776 align=center border=0>
<TBODY>
<TR>
<TD vAlign=top width=195 bgColor=#ffffff
height=186> <table width="193" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle"><a
href="<%=request.getContextPath()%>/news/showNewsList.jsp"><img
src="<%=request.getContextPath()%>/image/cg1_r1_c2.jpg"
width="175" height="25" border="0" /></a></td>
</tr>
<tr>
<td align="center" valign="middle"><a
href="<%=request.getContextPath()%>/product/showProductList.jsp"><img
src="<%=request.getContextPath()%>/image/cg1_r2_c2.jpg"
width="175" height="25" border="0" /></a></td>
</tr>
<tr>
<td align="center" valign="middle"><a
href="<%=request.getContextPath()%>/after.jsp"><img
src="<%=request.getContextPath()%>/image/cg1_r4_c2.jpg"
width="175" height="25" border="0" /></a></td>
</tr>
<tr>
<td align="center" valign="middle"><a
href="<%=request.getContextPath()%>/about.jsp"><img
src="<%=request.getContextPath()%>/image/cg1_r6_c2.jpg"
width="175" height="25" border="0" /></a></td>
</tr>
<tr height="1">
<td align="center" valign="middle">&nbsp;</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img
src="<%=request.getContextPath()%>/image/cg1_r10_c1.jpg"
width="188" height="28" /></td>
</tr>
<tr>
<td width="33"><img
src="<%=request.getContextPath()%>/image/cg5_1.jpg" width="21"
height="28" /></td>
<td width="158" class="d06">业务专线:010-88888888</td>
</tr>
<tr>
<td width="33" colspan="2"><img
src="<%=request.getContextPath()%>/image/tiao.jpg" /></td>
</tr>
<tr>
<td width="33"><img
src="<%=request.getContextPath()%>/image/cg5_1.jpg" width="21"
height="28" /></td>
<td width="158" class="d06">售后服务:010-66666666</td>
</tr>
<tr>
<td width="33" colspan="2"><img
src="<%=request.getContextPath()%>/image/tiao.jpg" /></td>
</tr>
<tr>
<td width="33"><img
src="<%=request.getContextPath()%>/image/cg5_1.jpg" width="21"
height="28" /></td>
<td width="158" class="d06">传&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;真:010-12345678</td>
</tr>
<tr>
<td width="33" colspan="2"><img
src="<%=request.getContextPath()%>/image/tiao.jpg" /></td>
</tr>
</table>
</td>
</tr>
</table>
</TD> <TD vAlign=top bgColor=#ffffff height=300>
<table cellspacing="0" cellpadding="4" width="100%" align="center"
border="0"> <tr>
<tbody>
<%
//遍历productList
for (int i = 0; i < productList.size(); i++) {
Product product = (Product) productList.get(i);
%>
<tr valign="top">
<td><a
href="<%=request.getContextPath()%>/product/detailProduct.jsp?productID=<%=product.getProductID()%>"
name="id"><img src="<%=request.getContextPath()%>/image/<%=product.getPicture()%>">
</a></td>
<td height="93">
<table cellspacing="1" cellpadding="4" width="100%"
bgcolor="#cccccc" border="0">
<tbody>
<tr valign="top" align="left" bgcolor="#ffffff">
<td height="30">
<table height="123" cellspacing="1" cellpadding="4" width="100%"
bgcolor="#cccccc" border="0" style="height: 123px;">
<tbody>
<tr bgcolor="#99ccff">
<td align="center" width="80" bgcolor="#f0f0f0">产品名称</td>
<td width="120" bgcolor="#ffffff"><a
href="<%=request.getContextPath()%>/product/detailProduct.jsp?productID=10"><font
color="#000000"><%=product.getName()%></font> </a></td>
<td align="center" width="80" bgcolor="#f0f0f0">产品品牌</td>
<td bgcolor="#ffffff"><font color="#ff0033"><%=product.getBrand()%></font>
</td>
</tr>
<tr style="DISPLAY: block" bgcolor="#99ccff">
<td align="center" width="80" bgcolor="#f0f0f0">产品型号</td>
<td bgcolor="#ffffff"><%=product.getSerialNumber()%></td> <td align="center" width="80" bgcolor="#f0f0f0">产品价格</td>
<td bgcolor="#ffffff"><font color="#ff0033"> <%=product.getPrice()%></font>元
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<%
}
int prepagenum = currentpage;
int nextpage = currentpage;
//判断当前的页数如果小于最大页数就+1
if (currentpage <= productDao.getPagesCount(pagesize)) {
nextpage = currentpage + 1;
}
//判断当前的页数如果大于最大页数就-1
if (currentpage > 0) {
prepagenum = currentpage - 1;
}
if (allProductList.size() > pagesize) {
%>
<tr>
<td colspan="7" align="right" bgcolor="#FFFFFF">
<%
if (prepagenum > 0) {
%> <a href="<%=request.getContextPath()%>/product/showProductList.jsp?page=<%=prepagenum%>">上一页</a> <%
  }
  if (nextpage <= productDao.getPagesCount(pagesize)) {
 %> <a href="<%=request.getContextPath()%>/product/showProductList.jsp?page=<%=nextpage%>">下一页</a> <%
  }
 %>
</td>
</tr>
<%
}
%>
</tbody>
</table>
</td>
</tr>
</BODY>
</HTML>
页面显示上一页  下一页两个超链接怎么看不见让我无法翻页

解决方案 »

  1.   


    java程序就不要写在jsp里面了 
    不方便调试
    debug一下就很明了了 特别是上一页 下一页哪里的if判断
      

  2.   

    你可以把你的分页封装一下,在后台判断完在传到前台去,这样把java嵌在jsp里不好。
    比如说你可以封装个page类,后台读取数据时判断上一页,下一页的情况,只把当前页传给jsp。
    要翻页只要传个id回去读取就可以了,读取出来再判断一下,上一页、下一页情况。
      

  3.   

    以前做个一个通用的分页代码,你看看有用不?
    --------------------------------------------------------------
    package com.bbs;import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    /*
     * @author PandaBrother 熊猫哥哥  ^_^
     * all right reserved
     */
    public class PageBreak {
    private  String type="";
    private  int totalPage = -1;//start with 1;
    private  int totalResult = -1;
    private  int currentPage = 1;//start with 1;
    private  int pageSize = 12;
    private  int showSize; 
     
    /* 
     * Constructor used to construct the totalResults and set the totoalPage; 
     */
       public void initPageBreak(Statement stmt ,String tableName,int currentPage,String conditions){
    String exesql = "select count(*) as totalRs from "+tableName+" where 1=1  "+ conditions;
    ResultSet rs = null;
    try{
    rs = stmt.executeQuery(exesql);
    int totalRs=0;
    if(rs!=null){
    if(rs.next()){
    totalRs = rs.getInt("totalRs");
    setTotalResult(totalRs);
    this.totalPage=(int)Math.ceil(totalRs/(pageSize+0.0))==0?1:(int)Math.ceil(totalRs/(pageSize+0.0));
    if(currentPage<=0){
    currentPage=1;
    }
    if(currentPage>totalPage){
    currentPage=totalPage;
    }
    this.currentPage=currentPage;
    }
    }
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    try {
    rs.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

    public int getTotalResult() {
    return totalResult;
    }
    public void setTotalResult(int totalResult) {
    this.totalResult = totalResult;
    } public int getTotalPage() {
    return totalPage;
    } public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
    } public int getCurrentPage() {
    return currentPage;
    } public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
    } public int getPageSize() {
    return pageSize;
    } public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
    }

    /*
     * before use this method in jsp or java ,you mast confirm you have 
     * set the variables currentPage and totalPage. and finally don't forget to close(rs) and  close(stmt) and  close(conn);
     * currentpage start with 1 and can't be less then zero;
     */
    public ResultSet getRsByPage(Statement stmt, String sql){
    sql += " order by mainid desc limit "+this.pageSize*(currentPage-1)+","+this.pageSize ;
    ResultSet rs=null;
    try {
     rs = stmt.executeQuery(sql);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return rs;
    }


    public String getPageLinkURL(String pageLink){
    StringBuffer sbf = new StringBuffer();
    if(totalPage==0 || totalPage==1){
    sbf.append("");
    return sbf.toString();
    }
        /*System.out.println("totalPage="+totalPage);
    System.out.println("currentPage="+currentPage);
    System.out.println("totalResult="+totalResult);
    System.out.println("(int)Math.ceil(totalPage/10)="+(int)Math.ceil(totalPage/10.0));
    System.out.println("currentPage/10)="+currentPage/10.0);
    System.out.println("(int)Math.ceil(currentPage/10)="+(int)Math.ceil(currentPage/10.0));*/
    if(this.currentPage!=1){
    if(pageLink.indexOf("?")!=-1){
    sbf.append("<a  href=\""+pageLink+"&cur_page=1\" >首页</a>&nbsp;");
    }else{
    sbf.append("<a  href=\""+pageLink+"?cur_page=1\" >首页</a>&nbsp;");
    }
    }

    if(this.totalPage>2){
    int t10 = (int)Math.ceil(totalPage/10.0);
    int c10 = (int)Math.ceil(currentPage/10.0);
    int is=1;
    int ie=1;

    // ascertain the pageLinks inline;

    if(c10==t10){is=(c10-1)*10+1;ie=totalPage;}else{is=(c10-1)*10+1;ie=(c10)*10;};

    //  
    /*System.out.println("totalPage="+totalPage);
    System.out.println("t10="+t10);
    System.out.println("c10="+c10);
    System.out.println("is="+is);
    System.out.println("ie="+ie);*/
    if(c10>1){
    if(pageLink.indexOf("?")!=-1){
    sbf.append("<a  href=\""+pageLink+"&cur_page="+(c10-1)*10+"\"><<</a>&nbsp;");
    }else{
    sbf.append("<a  href=\""+pageLink+"?cur_page="+(c10-1)*10+"\"><<</a>&nbsp;");
    }
    };

    //every 10 pageLink as a group
    for(int i=is;i<=ie;i++){
    if(this.currentPage==i){
    sbf.append("<font color=\"red\">"+i+"</font>&nbsp;");
    }else{
    if(pageLink.indexOf("?")!=-1){
    sbf.append("<a  href=\""+pageLink+"&cur_page="+i+"\">"+i+"</a>&nbsp;");
    }else{
    sbf.append("<a  href=\""+pageLink+"?cur_page="+i+"\">"+i+"</a>&nbsp;");
    }
    }
    }
    //every 10 pageLink as a group
    if(t10!=c10){
    if(pageLink.indexOf("?")!=-1){
    sbf.append("<a  href=\""+pageLink+"&cur_page="+((c10)*10+1)+"\">>></a>&nbsp;");
    }else{
    sbf.append("<a  href=\""+pageLink+"?cur_page="+((c10)*10+1)+"\">>></a>&nbsp;");
    }
    };

    }

    if(this.currentPage!=this.totalPage){
    if(pageLink.indexOf("?")!=-1){
    sbf.append("<a  href=\""+pageLink+"&cur_page="+this.totalPage+"\" >末页</a>");
    }else{
    sbf.append("<a  href=\""+pageLink+"?cur_page="+this.totalPage+"\" >末页</a>");
    }
    }

    return sbf.toString();
    }
    }
      

  4.   

    只能说明你当前页是第一页了,并且只有一页。
    问题可能:
    int currentpage = 1;
    int pagesize = 5;
    String parampage = request.getParameter("page");
    //parampage = null
    if (parampage != null) {
    currentpage = Integer.parseInt(parampage);
    }
    还有你那个productDao.getPagesCount(pagesize) 能不能写成一个全局变量,每次在判断里查一遍数据库会影响性能。