I. Preface (translated from Orion official site) This article describes how to define your own tag under OrionApplicationServer step by step, implement the tag function, and finally use a jsp example for testing. 2. create a tag to implement the tag function. 1. name package com. acme. mytags (to be the same as the original version, I will not change it) packagecom. 1. Preface (translated from Orion official site)
This article will introduce how to define your own tag under Orion Application Server step by step, implement the tag function, and finally use a jsp example for testing.
2. create a tag to implement the tag function.
1. name package: com. acme. mytags (to be the same as the original one, I will not change it)
Package com. acme. mytags;
2. import related class
Import javax. servlet. jsp .*;
Import javax. servlet. jsp. tagext .*;
3. implement the javax. servlet. jsp. tagext. Tag interface:
Public class HelloWorld implements Tag
{
4. define local variables
Private PageContext pageContext;
Private Tag parent;
5. implementation method for calling the label
Public int doStartTag () throws javax. servlet. jsp. JspException
{
Return SKIP_BODY;
}
Note: SKIP_BODY is returned in this method. if the label body is empty, this value is returned. Otherwise, the value EVAL_BODY_INCLUDE is returned.
6. call the implementation method of tag termination
Public int doEndTag () throws javax. servlet. jsp. JspException
{
Try
{
PageContext. getOut (). write ("Hello World! ");
}
Catch (java. io. IOException e)
{
Throw new JspException ("IO Error:" + e. getMessage ());
}
Return EVAL_PAGE;
}
In this way, "Hello World!" will be output at the end of the custom tag of the jsp file !"
7. not enough. we need to write down the following method:
Public void release (){}
For this simple example, the above method does not require any implementation.
8. the JSP container needs to call the following method:
Public void setPageContext (final javax. servlet. jsp. PageContext pageContext ){
This. pageContext = pageContext;
}
The JSP container uses the preceding method to call the tag, and the preceding method is used to set the PageContext of the tag.
9. the JSP container also calls the following method:
Public void setParent (final javax. servlet. jsp. tagext. Tag parent)
{
This. parent = parent;
}
The JSP container uses the preceding method to set the parent-Tag of the Tag, because the PageContext of each Tag must retain its parent Tag.
10. Finally, the implementation method is as follows:
Public javax. servlet. jsp. tagext. Tag getParent ()
{
Return parent;
}
}
11. compile tags.
III. descriptive tags
Now we will write an tracing file to describe the tag.
1. create a taglib. tld file,
2. taglib. tld is an XML text file. the XML header is as follows:
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.