joneric wennerstrom
joneric wennerstrom

Reputation: 301

jsp custom tags in Tomcat - tag instantiation

We have a web app that uses jsp custom tags. We are running it on both Weblogic 10 and Tomcat 6. Some of the tags do not work in Tomcat. We traced the error to the following difference between Weblogic and Tomcat.

In Weblogic, the jsp custom tag's constructor is called for each occurrence of the tag in a jsp. While in Tomcat, the jsp custom tag's constructor is called only once, at the first occurence of the tag, no matter how many times the tag is used on the jsp page.

Thus, in Tomcat, since our jsp custom tag had some optional attributes, subsequent invocations of the tag were re-using values assigned in previous calls. In Weblogic, the tag's constructor was called for each occurrence and hence the tag was initialized to default values for each occurrence of the tag within a jsp page.

Does anyone know of a way (via a tomcat config file entry, web.xml entry, etc) to tell Tomcat to instantiate a new Tag object each time a jsp custom tag is encountered on a jsp page?

Upvotes: 2

Views: 2583

Answers (1)

Aleksander Blomskøld
Aleksander Blomskøld

Reputation: 18542

A servlet container may or may not pool tag instances (according to the Java Servlet Specification). The best way to fix your problem should probably be to fix the way your tags are written. In your case it will probably be to do cleanup (set optional parameters to null) in the doEndTag() method.

If that is not feasible, you may disable tag pooling in Tomcat by putting this to your Tomcat installation's conf/web.xml:

 <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        (...)
        <init-param>
            <param-name>enablePooling</param-name>
            <param-value>false</param-value>
        </init-param>
        (...)
 </servlet>

Upvotes: 4

Related Questions