The key part is as follows. Process tags. In fact, in many cases, we use the provided taglib.
Other people/companies have completed tag and processing. After packaging, all we need to do is apply it in our jsp.
But when we make a taglib, We need to write this part of tag handler.
Here, only the insert tag mentioned in the above file is used. Other values are not described in detail to avoid duplication.
=============================== InsertTag. java ==================================
/*
* $ Id: InsertTag. java, v 1.13 2000/03/04 02:54:57 brydon Exp $
* Copyright 1999 Sun Microsystems, Inc. All rights reserved.
* Copyright 1999 Sun Microsystems, Inc. Tous droits Ré servé s.
*/
Package com. sun. estore. taglib;
Import javax. servlet. jsp. JspTagException;
Import javax. servlet. jsp. tagext. TagSupport;
Import com. sun. estore. util. Debug;
/**
* This class is an easy interface to the JSP template or other
* Text that needs to be inserted.
* @ Author Greg Murray
*/
Public class InsertTag extends TagSupport {
Private boolean directInclude = false;
Private String parameter = null;
Private String templateName = null;
Private Template template = null;
Private TemplateParameter templateParam = null;
/**
* Default constructor
*/
Public InsertTag (){
Super ();
}
Public void setTemplate (String templateName ){
This. templateName = templateName;
}
Public void setParameter (String parameter ){
This. parameter = parameter;
}
Public int doStartTag (){
Try {
If (templateName! = Null ){
Template = (Template) pageContext. getRequest (). getAttribute ("template ");
}
} Catch (NullPointerException e ){
Debug. println ("Error extracting template from session:" + e );
}
If (parameter! = Null & template! = Null) templateParam = (TemplateParameter) template. getParam (parameter );
If (templateParam! = Null) directInclude = templateParam. isDirect ();
Return SKIP_BODY;
}
Public int doEndTag () throws JspTagException {
Try {
PageContext. getOut (). flush ();
} Catch (Exception e ){
// Do nothing
}
Try {
If (directInclude & templateParam! = Null ){
PageContext. getOut (). println (templateParam. getValue ());
} Else if (templateParam! = Null ){
If (templateParam. getValue ()! = Null) pageContext. getRequest (). getRequestDispatcher (templateParam. getValue (). include (pageContext. getRequest (), pageContext. getResponse ());
}
} Catch (Throwable ex ){
Ex. printStackTrace ();
}
Return EVAL_PAGE;
}
}
You can see. InsertTag. java inherits the javax. servlet. jsp. tagext. TagSupport class because some interfaces are defined in TagSupport.