JSP paging program with high efficiency

Source: Internet
Author: User
Tags odbc

You can jump to a specific page by using the dropdown box

<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>
<%
Connection M_connection=null;
Statement M_statement=null;
ResultSet M_resultset=null;
String SQL;
String DBPath = Application.getrealpath ("/Database Location"); Convert a relative path into a physical path
String connstr = "Jdbc:odbc:driver={microsoft Access Driver (*.mdb)};D bq=" +dbpath;
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
M_connection=drivermanager.getconnection (CONNSTR);
M_statement=m_connection.createstatement (1004,1007);
sql= query statement;
M_resultset=m_statement.executequery (SQL);
%>
<div>
<table class= "list" width= "580" >
<%
int i=1;
int rscount=0;//Record Bar number
int allpages=1;//All pages
if (m_resultset!=null)
{m_resultset.last ();
Rscount=m_resultset.getrow ();
if (rscount>0)
{ALLPAGES=RSCOUNT/10;
if (rscount> (Allpages *)) {allpages=allpages+1;}
if (curpage==1) {M_resultset.first ();}
Else{m_resultset.absolute (10* (curpage-1) +1);}
while (!m_resultset.isafterlast ())
{%>
&LT;TR valign= "Top" height= ">"
<td><%=m_resultset.getstring ("D_d_name")%></td>
<td><%=m_resultset.getstring ("D_t_name")%></td>
<td><input style= "margin:0px type=" button "Name=" Submit2 "onclick=" Actiondo (' del ', ' <%=m_ Resultset.getstring ("d_d_id")%> ', ' <%=curpage%> ') "value=" delete "><input style=" margin:0px; "Type=" Button "Name=" Submit3 "onclick=" Actiondo (' edit ', ' <%=m_resultset.getstring ' d_d_id ')%> ', ' <%=curpage%> ') ' value= "edit" ></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; page:</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) ' > Home </a>");}
Else
{Out.print ("Home");}
%>
</font>
<font color= ' #000080 ' >
<%if (Curpage!=1)
{Out.print ("<a href= ' javascript:previouspage () ' > Prev </a> ');}
Else
{out.print ("Up page");}
%>
</font>
<font color= ' #000080 ' >
<% if (allpages!=0&& (curpage<allpages))
{Out.print ("<a href= ' javascript:nextpage () ' > next page </a>");}
Else
{out.print ("next page");}
%>
</font>
<font color= ' #000080 ' >
<% if (allpages!=0&& (curpage<allpages))
{Out.print ("<a href= ' Javascript:gopagebyno (" +allpages+ ") ' > Last </a> ');}
Else
{Out.print ("last");}
%>
</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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.