How Custom Tag Works
This section provides a simple description of how custom tag works in JSP pages. Custom tags are independent of JSTL libraries.
Here is my understanding of how custom tag works, using the "Hello world!" tag as
- When "hello_tag.jsp" page is requested for the first time, Tomcat server will
convert the JSP page into a Java servlet class.
- When the <hy:hello/> custom tag is encountered during the conversion,
Tomcat server will follow the TLD file to locate the HelloTag.class file.
Note that the TLD file is provided in the "jsp:root" element.
- Then Tomcat server will replace the custom tag with some Java code
to instantiate an object of the tag class, initialize the object, and call
the doStartTag() method.
- To output data into page, you can get an output stream from the
pageContext object provided by the JSP tag extension facility, pageContext.getOut().
This is how the "Hello world!" message gets produced in the IE window.
- Note that I do not need to use <jsp:directive.page import="herong.HelloTag"/>
to import the tag class into the JSP page.
Custom tags are independent of JSTL technology. You don't need to install the JSTL API JAR file or
any JSTL implementation JAR file to create and use your own custom tags.
Table of Contents
About This Book
JSP (JavaServer Pages) Overview
Tomcat 7 Installation on Windows Systems
JSP Scripting Elements
Java Servlet Introduction
JSP Implicit Objects
Syntax of JSP Pages and JSP Documents
JSP Application Session
Managing Cookies in JSP Pages
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Performance of JSP Pages
EL (Expression Language)
Overview of JSTL (JSP Standard Tag Libraries)
JSTL Core Library
►JSP Custom Tags
What Is Custom Tag?
Creating and Using Custom Tags
My First Custom Tag - hy:hello
►How Custom Tag Works
JSP Java Tag Interface
Custom Tag Attributes
Multiple Tags Working Together
File Upload Test Application
PDF Printing Version