Jsp custom tag

Source: Internet
Author: User
Tags tld

 

1. Compile an implementation class that implements the tag Interface

2. Describe the tag processor class in the tld file (under the WEB-INF directory)

You can copy and modify the xml code in E: \ study \ tomcat \ apache-tomcat-7.0.22 \ apache-tomcat-7.0.22 \ webapps \ examples \ WEB-INF \ jsp2

Class3g. tld

 

<? Xml version = "1.0" encoding = "UTF-8"?>

 

<Taglib xmlns = "http://java.sun.com/xml/ns/j2ee"

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

Xsi: schemaLocation = "http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"

Version = "2.0">

<Description> There are my custom tags. </description>

<Tlib-version> 1.0 </tlib-version>

<Short-name> Class3g </short-name>

<Uri> http://www.class3g.com </uri>

<Tag>

<Description> showthe romete address </description>

<Name> viewIP </name>

<Tag-class> class3g. web. tag. ViewIpTag </tag-class>

<Body-content> empty </body-content>

</Tag> www.2cto.com

</Taglib>

3. import and use custom tags in jsp

<% @ Taglib uri = "http://www.class3g.com" prefix = "class3g" %>

Lifecycle of the TagSupport class

Create a tag processing object, then store the property value of the custom tag to the tag processing object, pass the value in, call the doStartTag () method, doStartTag () if the method returns the SKIP_BODY TAG body, it will not be executed and will directly go to the doEndTag () method. If the doEndTag () method returns EVAL_PAGE, you need to focus on other content of the JSP webpage, if SKIP_PAGE is returned, other content of the JSP page is ignored. If the doStartTag () method returns EVAL_BODY_INCLUDE, the TAG body is executed. If the doAfterBoda () method is not overwritten, The SKIP_BODY is returned. The TAG body is displayed once and then the doEndTag () method is run; if doAfterBoda () is overwritten, after the label content is displayed for the first time, EVAL_BODY_AGAIN is returned, and the subject content is re-displayed until SKIP_BODYZ is returned to run the doEndTag () method.

 

Author: Cheng Long

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.