background image

Tag Handlers

<< The getServletContext() Method | Screen Definitions >>
<< The getServletContext() Method | Screen Definitions >>

Tag Handlers

"Rollback failed: "+e.getMessage());
e.printStackTrace();
}
}
}
try {
request.
getRequestDispatcher(
"/template/template.jsp").
forward(request, response);
} catch(Exception ex) {
ex.printStackTrace();
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) {
request.setAttribute(
"selectedScreen",
request.getServletPath());
try {
request.
getRequestDispatcher(
"/template/template.jsp").
forward(request, response);
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
Tag Handlers
The template tag library contains four tag handlers (DefinitionTag, ScreenTag,
ParameterTag
, and InsertTag) that demonstrate the use of cooperating tags. DefinitionTag,
ScreenTag
, and ParameterTag constitute a set of nested tag handlers that share private objects.
DefinitionTag
creates a public object named bookstore that is used by InsertTag.
In doTag,
tut-install/javaeetutorial5/examples/web/bookstore3/src/java/com/sun/bookstore3/template/DefinitionTag.java
creates a private object named screens that contains a hash table of screen definitions. A screen
definition consists of a screen identifier and a set of parameters associated with the screen.
These parameters are loaded when the body of the definition tag, which contains nested screen
and parameter tags, is invoked. DefinitionTag creates a public object of class
tut-install/javaeetutorial5/examples/web/bookstore3/src/java/com/sun/bookstore3/template/Definition.java,
selects a screen definition from the screens object based on the URL passed in the request, and
uses this screen definition to initialize a public Definition object.
Programming Simple Tag Handlers
The Java EE 5 Tutorial · September 2007
270