I. Foreword (this article is translated from Orion Official Site) This article describes one step in the Orion Application Server to define its own label, then implement the tag function, and finally test with a JSP example. Second, establish a label to implement the function of the label. 1. Named package is: com.acme.mytags (in order to be the original text, I don't make a change) Package com.acme.mytags; 2.import related classimport javax.servlet.jsp. *; Import javax.servlet.jsp.tageXT . *; 3 javax.servlet.jsp.tagext.Tag implement the interface: public class HelloWorld implements tag {4. define local variables private PageContext pageContext; private tag parent; 5. method of calling tag begins public int doStartTag () throws Javax.Servlet.jsp.jspexception {return Skip_body;} Note: This method returns Skip_body, which is when the tag's body is empty, otherwise it will return: evAl_body_include6. Public INT DOENDTAG () THROWS JAVAX.SERVLET.Jsp.jspexception {Try {pageContext.get (). Write ("Hello World!");} catch (java.io.ioException e) {throw new JSPEXCEPTION ("IO Error:" E.getMessage ());} return evAl_page;} This will end the "Hello World!" 7. Isn't enough, we still have to write the following method: public void release () {} is simple Example, the above method does not require any implementation. 8.Jsp's container To call the following method: public void setPageContext (Final Javax.Servlet.jsp.pageContext PageContext) {this.pageContext = pageContext;} JSP container calls the label through the above method, and the above method is used to set the label PageContext.9.jsp's container also calls the following method: public void setparent (Final Javax.Servlet.jsp.tagext.tag parent) {this.parent = parent;} JSP container set the tag for the tab with the above method- Tag, because each tag's PageContext must keep its Parent tag. 10. Finally, implement the method: public javax.servlet.jsp.tagext.tag getparent () {return parent;}} 11. Compiling tags. Third, the descriptive tag will now write a squeezed file to describe the label.
1. Create a taglib.tld file, 2. Taglib.tld is a text file in XML format, XML's head is as follows: XML Version = "1.0" Encoding = "ISO-8859-1"> 3. Describe Tag Library < Taglib>
body> html> 6, the test runs in the Orion directory, established the following structure, where Tag is built by itself, the previous directory is original. E: / orion / default-web-app / tag puts all JAR files and JSP files all in this directory. Then, access: http:// localhost: [port] /tag/hello.jsp will appear: ---------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------- Hello World! --------- -------------------------------------------------- ------- Seven, congratulations, you have succeeded! Attached: mytags.jar and hello.jsp files download address: http://www.wodejia.net/softdownload/java/orion_tag01.zip