JSP implementation is similar to Baidu Google Paging

Source: Internet
Author: User

<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Page import = "com. modorn. Bean. userdao" %>
<% @ Page import = "com. modorn. Bean. userbean" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + "://"
+ Request. getservername () + ":" + request. getserverport ()
+ Path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'manger. jsp 'starting page </title>

<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
<Style type = "text/CSS">
Table {border-collapse: collapse ;}
TD {border: # CCC solid 1px; padding: 5px ;}
</Style>

</Head>

<Body>
<%! Int pagenow = 1; %>

<%
String username = (string) request. getsession (). getattribute ("username ");
If (username = NULL ){
Response. sendredirect ("login. jsp? Erro = 1 ");
}
If (request. getparameter ("pagenow ")! = NULL ){
Pagenow = integer. parseint (request. getparameter ("pagenow "));
}
%>
<Center>

Welcome
<Font color = Red> <% = username %> </font> log on
<Br/>
<Br/> will military training last very dark for 10 days?
<Br/>
<%
Userdao = new userdao ();
Int pagenum = userdao. getpagenum ();
Arraylist <userbean> List = userdao. fenyeinfo (pagenow );
Int countpage = userdao. getcounpage ();
%>

<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TH>
User ID
</Th>
<TH>
User Name
</Th>
<TH>
Password
</Th>
<TH>
User Type
</Th>
</Tr>
<%
For (INT I = 0; I <list. Size (); I ++ ){
Out. println ("<tr> <TD>" + list. Get (I). getuserid () + "</TD> ");
Out. println ("<TD>" + list. Get (I). GetUserName () + "</TD> ");
Out. println ("<TD>" + list. Get (I). getpassw () + "</TD> ");
Out. println ("<TD>" + list. Get (I). getgrade () + "</TD> </tr> ");
}
%>
</Table>

<! -- Paging Algorithm Start -->

<%
If (pagenow! = 1 ){
Out. println ("<a href = manger. jsp? Pagenow = "+ (pagenow-1)
+ "> Previous page </a> ");
}
Int start;

If (pagenow <pagenum ){
Start = 1;
} Else {
Start = pagenow-10 + 1;
}

For (INT I = start; I <= countpage & I <= pagenow + pagenum; I ++ ){
If (I = pagenow ){
Out. println (I); what can be used to remove black circles
Continue;
}
Out. println ("<a href = manger. jsp? Pagenow = "+ I +"> ["+ I
+ "] </A> ");
}
If (pagenow! = Countpage ){
Out. println ("<a href = manger. jsp? Pagenow = "+ (pagenow + 1)
+ "> Next page </a> ");
}
%>
<! -- End of paging algorithm -->
</Center>

</Body>
</Html>

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.