Servlet Class Converted from JSP -

This section describes the Servlet class converted from my test JSP page,, which shows you how the custom tag, hy:trace, is converted.

As we all know that JSP pages are converted into Servlet classes before execution. So we can actually review the converted Servlet class to see how the tag extension facility connects the Servlet class to the tag class.

To review the Servlet class converted from TraceTagTest.jspx, open in \local\tomcat\work\Catalina\localhost\ROOT\org\apache\jsp, you will see:

 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/9.0.12
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class TraceTagTest_jspx
    extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =

  private static java.util.Map<java.lang.String,java.lang.Long>

  static {
    _jspx_dependants =
       new java.util.HashMap<java.lang.String,java.lang.Long>(1);
       "/WEB-INF/tlds/HyTaglib.tld", Long.valueOf(1352927783540L));

  private org.apache.jasper.runtime.TagHandlerPool

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long>
     getDependants() {
     return _jspx_dependants;

  public void _jspInit() {
       = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(
       = _jspxFactory.getJspApplicationContext(
       = org.apache.jasper.runtime.InstanceManagerFactory

  public void _jspDestroy() {

  public void _jspService(
        final javax.servlet.http.HttpServletRequest request,
        final javax.servlet.http.HttpServletResponse response)
        throws, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

    try {
      pageContext = _jspxFactory.getPageContext(
      this, request, response, null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      if (_jspx_meth_hy_005ftrace_005f0(_jspx_page_context))
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch ( e) {}
        if (_jspx_page_context != null)
        else throw new ServletException(t);
    } finally {

  private boolean _jspx_meth_hy_005ftrace_005f0(
          javax.servlet.jsp.PageContext _jspx_page_context)
          throws java.lang.Throwable {
    javax.servlet.jsp.PageContext pageContext = _jspx_page_context;
    javax.servlet.jsp.JspWriter out = _jspx_page_context.getOut();
    //  hy:trace
    herong.TraceTag _jspx_th_hy_005ftrace_005f0 = (herong.TraceTag)
    // /TraceTagTest.jspx(10,28) name = myAtt type = java.lang.String
       reqTime = false required = false fragment = false deferredValue
       = false expectedTypeName = null deferredMethod
       = false methodSignature = null
    _jspx_th_hy_005ftrace_005f0.setMyAtt("my value");
    int _jspx_eval_hy_005ftrace_005f0
       = _jspx_th_hy_005ftrace_005f0.doStartTag();
    if (_jspx_eval_hy_005ftrace_005f0
       != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
      do {
        out.write("JSP body");
        int evalDoAfterBody
           = _jspx_th_hy_005ftrace_005f0.doAfterBody();
        if (evalDoAfterBody
           != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
      } while (true);
    if (_jspx_th_hy_005ftrace_005f0.doEndTag()
       == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      return true;
    return false;

As you can see, the entire hy:trace element was translated into a method call, _jspx_meth_hy_005ftrace_005f0(_jspx_page_context). In that method, an object was instantiated from my trace tag class. Then interface methods were called one by one in the same order as we discussed in the previous section. The "do" loop was there to re-evaluate the body based on the returning flag of doAfterBody() call.

After finishing this trace tag example, I had a very good understanding of how the tag interface offered by the extension facility works now. How about you?

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 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

JSP Java Tag Interface

 javax.servlet.jsp.tagext.* Package

 javax.servlet.jsp.tagext.IterationTag Interface

 IterationTag Interface Test Class -

 IterationTag Interface Test JSP - TraceTagTest.jspx

Servlet Class Converted from JSP -

 TagSupport Class - Dummy Implementation of IterationTag

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Using Tomcat on CentOS Systems

 Using Tomcat on macOS Systems

 Connecting to SQL Server from Servlet

 Developing Web Applications with Servlet

 Archived Tutorials


 Full Version in PDF/EPUB