Jsp custom Tab

Source: Internet
Author: User

It took me a morning to study the custom tags. A custom page tag is created. The code is not carefully optimized. Post it first ,:)

1. Implementation class NumenTag. java of labels

Import java. util. ArrayList;
Import java. util. HashMap;
Import java. util. List;
Import java. util. Map;

Import javax. servlet. jsp (preferred for SUN Enterprise Applications). jsp (preferred for SUN Enterprise Applications) Exception;
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). jsp (preferred for SUN Enterprise Applications) Writer;
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). tagext. TagSupport;

/***//**
* Custom tab pages
*
* @ Author ma Wanlin
*
*/
Public class NumenTag extends TagSupport {

Private String url = null;

Private Result result;

Private String page = null;

Private String [] p;

Private Map kv = new HashMap ();

Private List key = null;

/***//**
* Separation Parameters
* @ Param params
*/
Public void setParams (String params ){
Key = new ArrayList ();
P = params. split (";");
For (int I = 0; p. length> 1 & I <p. length; I ++ ){
Kv. put (p [I]. split (":") [0], p [I]. split (":") [1]);
Key. add (p [I]. split (":") [0]);
}
}

/***//**
* Paging results
* @ Param result
*/
Public void setResult (String result ){
This. result = (Result) pageContext. getRequest (). getAttribute ("result ");
This. page = (String) pageContext. getRequest (). getAttribute ("page ");
}

Public void setUrl (String url ){
This. url = url;
}

Public int doStartTag () throws jsp (preferred for SUN Enterprise Applications) Exception {
StringBuffer sb = null;
If (result! = Null & result. getContent ()! = Null
& Result. getContent (). size ()> 0 ){
Sb = new StringBuffer ("Paging :");
If (result. getPage (). getHasPrePage ()){
Sb. append ("<a href ="). append (url );
If (url. indexOf ("? ") =-1)
Sb. append ("? Page = 1 ");
Else
Sb. append ("& page = 1 ");
LinkParams (sb );
Sb. append (">"). append ("Homepage"). append ("</a>"). append ("| ");
Sb. append ("<a href ="). append (url );
If (url. indexOf ("? ") =-1)
Sb. append ("? Page = "). append (
Result. getPage (). getPreviousPage ());
Else
Sb. append ("& page ="). append (
Result. getPage (). getPreviousPage ());
LinkParams (sb );
Sb. append (">"). append ("Previous Page"). append ("</a>"). append ("| ");
}
If (result. getPage (). getHasNextPage ()){
Sb. append ("<a href ="). append (url );
If (url. indexOf ("? ") =-1)
Sb. append ("? Page = "). append (result. getPage (). getNextPage ());
Else
Sb. append ("& page ="). append (result. getPage (). getNextPage ());
LinkParams (sb );
Sb. append (">"). append ("next page"). append ("</a>"). append ("| ");
Sb. append ("<a href ="). append (url );
If (url. indexOf ("? ") =-1)
Sb. append ("? Page = "). append (result. getPage (). getTotalPage ());
Else
Sb. append ("& page ="). append (result. getPage (). getTotalPage ());
LinkParams (sb );
Sb. append (">"). append ("last page"). append ("</a> ");
}
Sb
. Append ("Jump to: <select name = goToPage onchange = javascript: goPage (this. value)> ");
Int s = result. getPage (). getTo

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.