Design Tag Handler Classes for Instance Pooling
A JSP
container is allowed to reuse a tag handler instance to improve
performance, as long as it adheres to the strict rules defined in the
JSP specification. Briefly, the rules state that a tag handler
instance can be used for more than one occurrence of the
corresponding custom action element, in the same or different page,
only if the same set of attributes is used for all occurrences.
Before reusing the tag handler, the container must call the setter
methods for attributes that differ between the
occurrences (ensuring that the correct values are used for each
occurrence), but it’s not
required to call the setter methods for attributes with the same
value. You should therefore not do anything fancy in the setter
methods; just save the value in an instance value and do all the real
work in the doXXX( ) methods: doStartTag( )
,
doAfterBody( )
,
and doEndTag( )
.
While these rules guarantee consistent treatment of the setter
methods, they say nothing about how to deal with variable values that
are set through other means during the processing of the tag handler.
If you believe the release( )
method is called between each reuse of the tag handler, giving you a
chance to reset the internal state, you’re wrong,
but don’t feel bad—the JSP 1.1 specification
was unclear about this, and this misunderstanding about the
release( ) method is very common.
There’s also no guarantee that the
doEndTag( ) method is called; in case of an uncaught ...