jsp分页 史上最强

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page import="FFT.util.DB" %>
<%@ page import="java.sql.*" %>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<script language="javascript">
     function gopage()
     {
      document.listpage.submit();
     }
     function previouspage()
     {
      if ( (parseInt(document.listpage.page.value) ) < 1)
        document.listpage.page.value = 1;
      else
      {
        document.listpage.page.value = parseInt(document.listpage.page.value) - 1;
        document.listpage.submit();
      }
     }
     function nextpage()
     {
      document.listpage.page.value = parseInt(document.listpage.page.value) + 1;
         document.listpage.submit();
     }
     function gopagebyno(pageno)
     {
      document.listpage.page.value = pageno;
      document.listpage.submit();
     }

    </script>
    <%
			DB db = new DB();
			String sql="select * from vehicle_info";
		ResultSet m_ResultSet = db.query(sql);

    %>
     <div>
       <table class="list" width="580" >
         <%
     int i=1;
     int rscount=0;//记录条数
     int allpages=1;//所有页数
     //int curpage=1;
	 //out.write(curpage);
	 String s=request.getParameter("page");
	 out.write(s);
	 if(s==null)
	 	s="1";
		//int curpage=1;
	 int curpage=Integer.parseInt(s);
	
     if(m_ResultSet!=null)
       {m_ResultSet.last();
               rscount=m_ResultSet.getRow();
        if(rscount>0)
            {allpages=rscount / 10;
              if(rscount>(allpages * 10)){allpages=allpages+1;}
               if(curpage==1){m_ResultSet.first();}
                      else{m_ResultSet.absolute(10*(curpage-1)+1);}
               while(!m_ResultSet.isAfterLast())
                       {%>
         <tr valign="top" height="15">
                         <td><%=m_ResultSet.getString(1)%></td>
           <td><%=m_ResultSet.getString(2)%></td>
           <td><input  style="margin:0px;" type="button" name="Submit2" onClick="actiondo('del','<%=m_ResultSet.getString(3)%>','<%=curpage%>')" value="删除"><input  style="margin:0px;"  type="button" name="Submit3" onClick="actiondo('edit','<%=m_ResultSet.getString(4)%>','<%=curpage%>')" value="编辑"></td>
                       </tr>
         <%
                        i++;
                        if(i>10){break;}
         m_ResultSet.next();
                       }
      }
                  m_ResultSet.close();
       }
           %>
    </table>
    </div>
    <div align="center">
        <form name="listpage">
     <font color='#000080'>&nbsp;页次:</font>
     <b><font color=red><%=curpage%></font></b><font color='#000080'>/<b><%=allpages%></b>&nbsp;</font>
     <font color='#000080'>
     <% if (curpage!=1)
       {out.print("<a href='javascript:gopagebyno(1)'>首页</a>");}
      else
      {out.print("首页");}
      %>
     </font>
     <font color='#000080'>
     <%if(curpage!=1)
          {out.print("<a href='javascript:previouspage()'>上页</a>");}
         else
       {out.print("上页");}
      %>
      </font>
     <font color='#000080'>
     <% if(allpages!=0&&(curpage<allpages))
         {out.print("<a href='javascript:nextpage()'>下页</a>");}
         else
        {out.print("下页");}
     %>
             </font>
     <font color='#000080'>
     <% if(allpages!=0&&(curpage<allpages))
         {out.print("<a href='javascript:gopagebyno("+allpages+")'>尾页</a>");}
        else
        {out.print("尾页");}
     %>
            </font>
     <select name="page" onChange="javascript:gopagebyno(document.listpage.page.value)" >
     <%for(i=1;i<=allpages;i++)
         {if(curpage==i){out.print("<option value='"+i+"' selected='selected'>"+i+"</option>");}
      else{out.print("<option value='"+i+"'>"+i+"</option>");}
         }
     %>
     </select>
       </form>
    </div>
</body>
</html>

你可能感兴趣的:(html,sql,jsp,XHTML)