File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes detecting taglib present or missing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "detecting taglib present or missing" Watch "detecting taglib present or missing" New topic

detecting taglib present or missing

chris coleman
Ranch Hand

Joined: Mar 06, 2002
Posts: 42
Suppose you're writing a jsp page that is meant to use certain tags out of a given taglib.
And what if the jsp page uses tags that do not exist in any imported taglib...? Maybe you are inadvertently importing an older version of the taglib.
Will those tags will simply not generate any visible output on the screen?
How could you detect the missing tag code and redirect the user to a page that says.. "hey, you have to install the xxxxxx taglib." ?

Sun Certified Java Programmer for the Java2(tm) Platform<br />IBM Certified Solution Developer, WebSphere 3.5
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
In event of usage of wrong version of taglib, compiling of JSP page itself will be a problem
Billy Bacon

Joined: Apr 03, 2003
Posts: 2
If you attempt to use a tag that the compiler cannot find in a tag library due to not import the taglib directive it resides in or if the .tld file doesn't contain the tag you are attempting to use, the comiler should complain that it knows nothing about the tag you are using and throw an error.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
If you're using an incorrect prefix, then the compiler has no way of telling since those tags might actually be a part of your output. After all, you could be using JSP to generate XML instead of HTML. However, if you've got the prefix correct and the tag name incorrect, you will get an error from the JSP compiler.
If you really want to add some validation to the page, to check for old versions of tags for example, check out the TagLibraryValidator class from the javax.servlet.jsp.tagext package.
I agree. Here's the link:
subject: detecting taglib present or missing
It's not a secret anymore!