Pagination in JSP-pagination label class

Source: Internet
Author: User
Package com. dbtemplate. Tag;

Import java. Io. ioexception;

Import javax. servlet. http. httpsession;
Import javax. servlet. jsp. jspexception;
Import javax. servlet. jsp. jspwriter;
Import javax. servlet. jsp. tagext. tagsupport;

Import org. Apache. log4j. Logger;

Import com. dbtemplate. domain. pageinfo;

/***//**
* <PRE>
* Paginationtag is a JSP custom tag. Its functions are as follows:
* Provide paging information for the page
*
* The process is as follows:
*. Get the pageinfo object stored in the session.
* Print paging information based on a series of tags in pageinfo
*
* </PRE>
*
* @ Author Peng
*
*/
Public class paginationtag extends tagsupport ...{

Static logger = logger. getlogger (paginationtag. Class. getname ());

Static final string baseurl = "<a href =" user. jsp? ";

Static final string endtag = "</a> ";

/**//*
* Page <% = intpage %> total <% = intpagecount %> pages (total <% = introwcount %> Records)
*
* <! -- Display the homepage link --> <a href = "user. jsp? "> Homepage </a>
*
* <! -- Show Previous Page Link --> <% IF (intpage> 1) {%> <a href = "user. jsp? Page = intPage-1 %> "> previous </a>
* <%}%>
*
* <! -- Display next page Link --> <% IF (intpage <intpagecount) {%> <a href = "user. jsp? Page = <% = intpage + 1%> "> next page </a>
* <%}%>
*
* <! -- Display the last link --> <a href = "user. jsp? Page = <% = intpagecount %> "> last page </a>
*
* <! -- Display the refresh data link --> <a onclick = "window. Location. Reload ();"
* Onmouseover = "This. style. textdecoration = 'underline';" onmouseout =
* "This. style. testdecoration = 'none';" style = "cursor: hand;"> refresh data </a>
*/

Public int doendtag () throws jspexception ...{

Logger. debug ("start to handle pagination infomatin .");
// Obtain the pageinfo object stored in the session
Httpsession session = pagecontext. getsession ();
Pageinfo = (pageinfo) Session. getattribute ("page ");

// Display the page information based on the information in pageinfo
Jspwriter writer = pagecontext. getout ();
Stringbuffer output = new stringbuffer ();

// Page number display
Output. append (""). append (pageinfo. getcurrentpageno (). append ("page ");
Output. append ("(total"). append (pageinfo. gettotalrecords (). append ("Record )");

// Home Page
Output. append (baseurl). append (""> "). append (" Homepage "). append (endtag );

// Previous Page Link
If (pageinfo. ishaspreviouspage ())...{
Output. append (baseurl). append ("page ="). append (
Pageinfo. getpreviouspageno (). append (""> "). append (" Previous Page ")
. Append (endtag );
}

// Next page
If (pageinfo. ishasnextpage ())...{
Output. append (baseurl). append ("page ="). append (
Pageinfo. getnextpageno (). append (""> "). append (" next page ")
. Append (endtag );
}

// Last link
Output. append (baseurl). append ("page ="). append (pageinfo. gettotalpages ())
. Append (""> "). append (" last page "). append (endtag );

// Refresh the Page Link
Output. append ("<a onclik =" javascript: window. Location. Reload ();"");
Output
. Append ("onmouseover =" This. style. textdecoration = 'underline ;"");
Output. append ("onmouseout =" This. style. textdecoration = 'none ';"");
Output. append ("style =" cursor: hand ;"");
Output. append ("refresh ");
Output. append (endtag );

// Print the page information
Try ...{
Writer. println (output );
} Catch (ioexception IOE )...{
Logger. Error ("error occured when handle paginatin informatin .");
Throw new jspexception (IOE. getmessage ());
}

Return skip_body;
}
}

 

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.