Tag Files in JSP 2.0
This tips explains about what are the advantages in the Custom Tags in JSP 2.0. It also compares it with the previous JSP versions.
Lets look into the tips for more detail.
Developing custom tags in the previous JSP versions are tedious and it is considered as one of the complex task for the JSP developers. Because inorderto write a simple custom tag you have to learn many things and should have good knowledge on Java also. Apart from that you have to use Tag APIs to create a complete tag library. Any small mistake will cause the error and tag files will not work. To make the things easy for the JSP developers, JSP 2.0 has the advanced features for creating JSP custom tag libraries.
The following are the mandatory for writing the custom tags in previous versions:
- Writing and compiling a tag handler.
- Defining the tag that is associated with the tag handler.
- Creating the TLD(Taglib Descriptor) files.
What is Tag Files?
JSP 2.0 has introduced the concept called tag files, which are nothing but the simple files works like a JSP file. They define all the functionalities required for a custome tag. You are no longer required to write the Java file and compile it. These tag files are compiled dynamically by the JSP container. Even though, it is simple file, JSP container will convert these files into a Tag Library. But developers need not worry about them.
Tag files just work like an JSP pages, it has the following implicit objects:
- request -> javax.servlet.http.HttpServletRequest
- response -> javax.servlet.http.HttpServletResponse
- out -> javax.servlet.jsp.JspWriter
- session -> javax.servlet.http.HttpSession
- application -> javax.servlet.ServletContext
- config -> javax.servlet.ServletConfig
- jspContext -> javax.servlet.jsp.JspContext
All the abobe objects are available in the normal JSP files also.
All the tag files must be put under the folder WEB-INF/tags or you can create the sub directory under it. The directory name must be specified while importing the tags in JSP file as follows:
<%@ taglib prefix="tagFiles" tagdir="/WEB-INF/tags" %>
Tag Files Example
This tips explains only the very basic points about the new features in custom tags and Tag Files. You can find simple example on writing the custome tags in JSP 2.0.