Example Java Class Converted from a JSP Page

This section provides a tutorial example Java class converted by Tomcat from the JSP page, Hello_Scripting.jsp. Scripting elements included in the JSP page are converted correctly.

What is the location of those Servlet class files converted from my JSP pages by the Tomcat server? The answer is depending on the Tomcat version and configuration settings.

If you are using Tomcat with default settings, JSP pages deployed to the default application folder, .\webapps\ROOT, will be converted to Servlet class files in the default work folder, .\work\Catalina\localhost\_\org\apache\jsp. If you are using other versions of Tomcat, the Servlet class file location could be different.

Here is where I found the converted Servlet class file of my Hello-Scripting.jsp used in the previous tutorial:

JSP page location:
\local\tomcat\webapps\ROOT\Hello-Scripting.jsp

Converted Java source code location:
\local\tomcat\work\Catalina\localhost\_\org\apache\jsp
   \Hello_005fScripting_jsp.java

Compiled Java bytecode location:
\local\tomcat\work\Catalina\localhost\_\org\apache\jsp
   \Hello_005fScripting_jsp.class

Notice that:

Now let's see how the converted Java class looks like. Open Hello_005fScripting_jsp.java:

/*
 * 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 Hello_005fScripting_jsp
    extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

   private String greeting() {
      return "Scripting Elements:";
   }

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

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

  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() {
    _el_expressionfactory =
          _jspxFactory.getJspApplicationContext(
          getServletConfig().getServletContext()
          ).getExpressionFactory();
    _jsp_instancemanager =
org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(
          getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(
        final javax.servlet.http.HttpServletRequest request,
        final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, 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 {
      response.setContentType("text/html");
      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;

      out.write("<html><body>\r\n");
      out.write("<!-- Hello_Scripting.jsp\r\n");
      out.write(
"   Copyright (c) 2002 HerongYang.com. All Rights Reserved.\r\n");
      out.write("-->\r\n");
      out.write("<pre>\r\n");
      out.print( greeting() );
      out.write('\r');
      out.write('\n');
 out.println("Hello world!");
      out.write('\r');
      out.write('\n');
      out.print( "-- From JSP" );
      out.write("\r\n");
      out.write("</pre>\r\n");
      out.write("</body></html>\r\n");
    } 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 (java.io.IOException e) {}
        if (_jspx_page_context != null)
          _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

I don't see any surprises. Do you?

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat Installation on Windows Systems

JSP Scripting Elements

 What Are Scripting Elements

 Converting JSP Pages with Scripting Elements

 Example JSP Page with Scripting Elements

Example Java Class Converted from a JSP Page

 Mixing Static Data with Scriptlets for Compound Statements

 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

 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

 References

 Full Version in PDF/EPUB