aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Tag Handler confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Tag Handler confusion" Watch "Tag Handler confusion" New topic
Author

Tag Handler confusion

alex lamb
Greenhorn

Joined: May 31, 2002
Posts: 6
Hello all,
Can someone please clarify what this means to me please ! I've taken this snippet from the JSP spec.
Once all invocations on the tag handler are completed, the release method is invoked on it. ... The page compiler guarantees that release() will be invoked on the Tag Handler before the handler is relased to the GC

Let's say for a custom Foo tag handler class. It is embedded in a number of pages. The pages are requested in different requests. Does the JSP container create one tag handler class and process all of those requests that need to use the tag handler OR does it create a tag handler object per page and then garbage collect it once the request has been serviced completely ?
Also if I have a single page that uses a number of times the same custom tag, when does it's release() method actually get called and the object garbage collected?
Thanks so much for your insights !
alex
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
This (IMHO) is one of the most complicated bits of the JSP specifcation - mainly because of the way that it is written.
Essentially, it's up to the vendor of the container as to whether they support the pooling of tag handler instances. The easiest way to get your head around it all is to look at some of the servlets that get generated from JSPs. Resin and Tomcat 3.3, for example, support pooling, whereas Tomcat 4.0 doesn't. You'll notice this by the way that the handler instances are reused or re-created upon each invocation of the tag.
(as a side note, there are a set of rules that determine when and whether a tag handler gets reused or not)
This pooling/reuse affects when the release() method actually gets called, but in general, it gets called when the tag handler is no longer required. For those containers that don't reuse instances, the release() method is called sometime before the end of the page. for those that do reuse instances, it is called when those instances are taken out of service.
I actually devoted a fair chunk of a chapter to a detailed explanation of this in my book, Professional JSP Tag Libraries if you are interested, but I hope that helps.
Cheers
Simon
p.s. some sample chapters ("Body Tags" and "Tag Patterns") from the book are now available to download
alex lamb
Greenhorn

Joined: May 31, 2002
Posts: 6
Simon,
That's really quite helpful actually. I figure this is probably not going to be of great importance when studying for the SCWCD exam but it's something I wanted to wrap my head around for my own interest sake. I think I'll just take your explanation for now and look at it a bit later again.
Thanks alot for your help
alex
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5370
Hi Alex
Actually whenever container finds any custom tags it creates a new instant of your class which implements/extends one of class/interface of javax.servlet.jsp.tagext package.
and its finally block it calls release mathod.(which denotes end of your custom tag)
You can find in [UR_SERVER]/home/localhost/urWebApp/urjsp$jsp.java file which is created by your contatiner.
HTH
CMIW
[ June 11, 2002: Message edited by: Ravish Kumar ]

"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Yes, but this only happens on those containers that don't pool tag handler instances, such as Tomcat 4.0.
If you take a look at code generated by something like Resin, then you'll see that the instances are in fact reused. In addition to this, and depending on the container, those tag handler instances may be pooled for use on other pages, or they may only be reused on a single page.
Cheers
Simon
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5370
thanks a lot Simon !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag Handler confusion
 
Similar Threads
Problems with custom Tag
SCWCD 1.4 FREE Beta Voucher Info
preparation for SCWCD
To Hans: Classic Tag, Simple Tag and Tag files
My Study Notes !!!