Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Summary: this page provides information about how the JEE Analyzer handles JSP Tag Files.


As of JSP version 2.0, developers can implement custom tags by writing a "JSP like" file rather than coding a java handler and providing a tag library descriptor. These files are known as Tag Files and have the .tag extension. At runtime, the web container converts these files into java classes (Tag Handlers) and generates implicit tag library descriptors that it then uses. CAST's JEE Analyzer supports these files.

Processing Tag Files

Tag Files are available to JSP 2.0 Applications in two forms:

Unpackaged Tag Files

Tag Files are placed in a subdirectory of /WEB-INF/tags/ and do not require a TLD. CAST's JEE Analyzer generates an implicit tag library for each directory under and including /WEB-INF/tags/ (if at least one of the tags it contains is referenced in a jsp file or another tag file).

Given the following Tag Files...

  • /WEB-INF/tags/encode.tag
  • /WEB-INF/tags/foo/a.tag
  • /WEB-INF/tags/foo/b.tag
  • /WEB-INF/tags/bar/baz/
  • /WEB-INF/tags/bar/baz/d.tag

...the implicit TLD for each library has the following values:

  • tlib-version for the tag library. Defaults to 1.0.
  • short-name is derived from the directory name. If the directory is /WEB-INF/tags/, the short name is simply "tags". Otherwise, the full directory path (relative to the web application) is taken, minus the /WEB-INF/tags/ prefix. Then all / characters are replaced with -(hyphen), which yields the short name. Note that short names are not guaranteed to be unique.
  • A tag-file element is considered to exist for each tag file, with the following sub elements:
    - The name for each is the filename of the tag file, without the .tag extension.
    - The path for each is the path of the tag file, relative to the root of the web application.

So, for the example above, the implicit TLD for the /WEB-INF/tags/bar/baz/ directory would be as follows:

Code Block

Each implicit Tag Library will be materialized in the Analysis Service, beneath a Web Directory object that represents its containing folder. Since these tlds are implicit, they do not have a physical existence, so no code viewing (in CAST Enlighten) will be possible for these files, their child objects and all outgoing links.

Tag Files are searched for under the /WEB-INF/tags. So, all .tag in this folder or sub folder will be automatically taken into account. The following image depicts objects created in the Analysis Service (click to enlarge):

You may have noticed that attributes of tags that are implemented by Tag Files are attached to the file rather than the Tag object created from the tld. Java variables that correspond to these attributes are also generated in the Handler java code (like servlet code for jsp pages) then attached to the Tag File.

Assuming that encodeTagTest.jsp contains:

Code Block
<%@ taglib prefix="easy" tagdir="/WEB-INF/tags" %><easy:encode input="<br/> means changing line"/>

And encode.tag contains:

Code Block
<%@ attribute name="input" required="true" %><%!private String encodeHtmlTag(String tag) {if (tag==null)return null;for (int i=0; i<length; i++) {// ....}return encodedTag.toString();}%><%= encodeHtmlTag(input) %>

Then links between the objects shown above would be as follows (click to enlarge):

Packaged Tag Files

Tag Files can be packaged in the /META-INF/tags/ directory in a JAR file installed in the /WEB-INF/lib/ directory of the web application. Tags placed here are typically part of a reusable library of tags that can be used easily in any web application. When used in a JAR file, the path sub element of the tag-file element specifies the full path of the tag file from the root of the JAR. Therefore, it must always begin with /META-INF/tags/.

In this context, you should extract the Tag Files to an equivalent /META-INF/tags/ folder under your application root path (at the same level as the WEB-INF folder) before the JEE Analyzer can process them. Tag files bundled in a JAR require a tag library descriptor. No implicit tld is generated for these files. In addition, once .tag files and TLDs are located, processing is carried out in exactly same way as with Unpackaged Tag Files.