background image

The HttpServlet Class

<< A Template Tag Library | The getServletContext() Method >>
<< A Template Tag Library | The getServletContext() Method >>

The HttpServlet Class

The
tut-install/javaeetutorial5/examples/web/bookstore3/web/template/screendefinitions.jspf
page creates a definition for the screen specified by the request attribute
javax.servlet.forward.servlet_path
:
<tt:definition name=
"bookstore"
screen=
"${requestScope
[
'javax.servlet.forward.servlet_path']}">
<tt:screen id=
"/bookstore">
<tt:parameter name=
"title" value="Duke's Bookstore"
direct=
"true"/>
<tt:parameter name=
"banner" value="/template/banner.jsp"
direct=
"false"/>
<tt:parameter name=
"body" value="/bookstore.jsp"
direct=
"false"/>
</tt:screen>
<tt:screen id=
"/bookcatalog">
<tt:parameter name=
"title" direct="true">
<jsp:attribute name=
"value" >
<fmt:message key=
"TitleBookCatalog"/>
</jsp:attribute>
</tt:parameter>
<tt:parameter name=
"banner" value="/template/banner.jsp"
direct=
"false"/>
<tt:parameter name=
"body" value="/bookcatalog.jsp"
direct=
"false"/>
</tt:screen>
...
</tt:definition>
The template is instantiated by the Dispatcher servlet. Dispatcher first gets the requested
screen. Dispatcher performs business logic and updates model objects based on the requested
screen. For example, if the requested screen is /bookcatalog, Dispatcher determines whether
a book is being added to the cart based on the value of the Add request parameter. It sets the
price of the book if it's on sale, and then adds the book to the cart. Finally, the servlet dispatches
the request to template.jsp:
public class Dispatcher extends HttpServlet {
@Resource
UserTransaction utx;
public void doGet(HttpServletRequest request,
HttpServletResponse response) {
String bookId = null;
Book book = null;
String clear = null;
BookDBAO bookDBAO =
Programming Simple Tag Handlers
The Java EE 5 Tutorial · September 2007
268