How to prevent reuse of jsp tags after class loading

I have a problem when some attributes in tag files are pasted the next time the tag is used.

I think this is because the Tag class is loaded by class, and then the same instance is reused for every call. Therefore, the attributes that I do not set in subsequent calls are not null, as I would expect them to, and will contain deprecated values!

I want this to be gone. Does anyone know what management settings are in tomcat 6?

+6
java tomcat jsp-tags
source share
4 answers

Tomcat 7.0 uses tag concatenation:

http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html

JSP Custom Tag Pooling - Java objects created for custom JSP tags can now be merged and reused. This greatly improves the performance of JSP pages that use custom tags.

This page also says that web.xml may contain the enablePooling option for this and that its default value is true.

So, I would say that disabling tag reuse is not a good idea, as it will lead to some performance loss.

Tomcat 7.0 ensures that the state of the tag class remains unchanged between doStartTag () and doEndTag ():

http://tomcat.apache.org/tomcat-7.0-doc/jspapi/javax/servlet/jsp/tagext/Tag.html

The doStartTag and doEndTag methods can be called in a tag handler. Between these calls, the tag handler is supposed to contain the state that should be saved

But the same paragraph also indicates between the brackets that the object must have its properties stored after:

After calling doEndTag, the tag handler is available for further calls ( and is expected to retain its properties ).

So what I do is reset all local variables to default before returning doEndTag (). I did not find an explanation on how combining and reusing Tomcat tags is implemented (e.g. TagHandlerPool.java), so I think this is the safest option.

+7
source share

You need to clear the tag state between calls. You must do this in the doEndTag() method of your class, just before returning. At this point, you should set all null state variables.

+2
source share

In fact, only one instance of the tag is created each time. Did you declare static attributes?

+1
source share

Maybe a little late, but I had the same problem. It occurs when I set the Tag attributes with a null value to a value. Changing the value does not give any error, only installation.

So, I believe that the implementation for reusing tags does something like which attributes were set and canceled after the tag ended. If you set this attribute in your tag code, the tag pool does not know until reset taht attrbiute and saves its value.

Not sure if this is true, but suitable for my observations

+1
source share

All Articles