O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Tag-Handler Lifecycle and What It Means to You

Creating new objects is a relatively expensive operation in Java. For high-performance applications, it’s common to try to minimize the number of objects created and try to reuse the same objects instead. The lifecycle defined for a tag handler allows a tag handler instance to be reused within the code generated for JSP pages under certain circumstances.

The tag-handler lifecycle details are pretty complex and are mostly of interest to container developers. But you need to know how the lifecycle relates to instance reuse to ensure that your tag handlers work correctly in a container that takes advantage of reuse for improved performance. Figure 20-5 shows a state diagram for a tag handler that implements just the Tag interface.

Lifecycle for a tag handler implementing the Tag interface

Figure 20-5. Lifecycle for a tag handler implementing the Tag interface

When the tag instance is created, all instance variables have default values; then all setter methods (setPageContext( ), setParent( ), and all setters for attributes) are called. This brings the instance to a state where it’s initialized for use. The doStartTag( ) method is then called. This method may set instance variables to values that are valid only for the current invocation. The doEndTag( ) method is called if no exception is thrown by doStartTag( ) or while processing the element’s body. The tag handler instance may then be reused ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required