if (Templateparam.getvalue ()!= null) pagecontext.getrequest (). Getrequestdispatcher (Templateparam.getvalue ()). Include (Pagecontext.getrequest (), Pagecontext.getresponse ());
}
catch (Throwable ex) {
Ex.printstacktrace ();
}
return eval_page;
}
}
Can see. Inserttag.java inherits the Javax.servlet.jsp.tagext.TagSupport class. Because some interfaces are defined in the TagSupport.
When we handle the custom tag, we overload the doStartTag () and Doendtag () of the parent class, and if you define the Tag property in the TLD file, you need to define the corresponding Setxxx/getxxx method for each property in the tag handler.
In doStartTag (), the Templateparameter object is obtained from the Hashtable defined by the template class.
In Doendtag ()
Pagecontext.getrequest (). Getrequestdispatcher (Templateparam.getvalue ()). Include (Pagecontext.getrequest (), Pagecontext.getresponse ());
This is what is generated by the resource object (RequestDispatcher) that is returned through the context of the JSP page, as specified by the property value of tag.
doStartTag () and Doendtag () return values are static int defined in tag interface
Skip_body implied 0
Skip body evaluation. Valid return value for doStartTag and Doafterbody. Skip the handling of the body.
is to skip the code between the start and end tags.
Eval_body_include implied 1
Evaluate body into the existing out stream. Valid return value for doStartTag.
This is a illegal return value to doStartTag when the class implements Bodytag,
Since Bodytag implies the creation of a new bodycontent.
The contents of the body are exported to the existing output stream. Include JSP code, also can be output
Skip_page implied 5
Skip the rest of the page. Valid return value for Doendtag.
Ignore the remaining pages.
Eval_page implied 6
Continue evaluating the page. Valid return value for Doendtag ().
Continue to the following page
There are references to other classes in this class, and I'm not going to list them. You can do your own research.
Custom tag (custom tags) implements the Javax.servlet.jsp.tagext.Tag or Javax.servlet.jsp.tagext.BodyTag
Interface. Apply Javax.servlet.jsp.JspWriter to output.
TagSupport class provides an implicit implementation of the interface tag. Serialization of the braided data.
public class TagSupport extends Java.lang.Object implements Tag, java.io.Serializable
The Bodytagsupport class provides an implicit implementation of the interface Bodytag. Inherit TagSupport
public class Bodytagsupport Extendstagsupport implements Bodytag
We need to inherit TagSupport class or Bodytagsupport class when writing tag handler, and then Overload doStartTag () and Doendtag ().
can be further separated. Put the concrete implementation into the bean
The classes of these custom tags should be placed in web-inf/classes or Web-inf/lib
Finally, custom tag libraries is packaged into a. war file. For the. war file, a resource map is given as shown in the following illustration.
Control mappings by deploying descriptors.
The deployment descriptor is an XML file. Please refer to the relevant documentation for detailed information. This only means
This example is very simple, just use it as an exercise. You can also expand on your own and practice a few more ways. For example, the tag has attributes,
Tags with content, using bean processing logic, and so on
About packaging these files into a. war file. Here is not a detailed description. Please do it yourself according to the application server you use.
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.