JSP tag Creation

Source: Internet
Author: User
Basic steps:
1. First write the class, extends tagsupport class, and rewrite the method you need.
(Note: If you inherit the simpletagsupport class, you must put all the processing code in the dotag () method)
2. Configuration
Write a TLD file and configure a web. xml file
3. jsp call
Note: The example provided by Tomcat is a good imitation example.
If the class inherits from simpletagsupport, all operations must be placed in the dotag () method;
If the class inherits from bodytagsupport,
In bodytagsupport, dostarttag () is reset back to eval_body_buffered, and then the setbodycontent () and doinitbody () methods are executed. setbodycontent () sets the bodycontent object, it includes some standard text information, and the objects that export data to response in the processing process, after which it will enter doafterbody () you can restore the eval_body_again or skip_body.
If you inherit the simpletagsupport class, you can use the built-in example of tamcat.
Public class pagedivide extends bodytagsupport {
Public iterator;
Public object element;

Public int dostarttag () throws jspexception {
Try {
Database DB = new database ();
DB. INIT ();
Iterator = dB. getcourse (). iterator ();
} Catch (exception e ){
E. printstacktrace ();
}
If (iterator. hasnext ()){
Element = iterator. Next ();
Pagecontext. setattribute ("course", element );
}
Return eval_body_buffered;
}

Public int doafterbody (){
Try {
Bodycontent. writeout (this. getpreviousout ());
} Catch (ioexception e ){
E. printstacktrace ();
}
Bodycontent. clearbody ();
If (iterator. hasnext ()){
Element = iterator. Next ();
Pagecontext. setattribute ("course", element );
Return eval_body_again;
} Else
Return eval_page;
}
}

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.