Execution Result of CurrentTime.jspx

This section describes execution result of the CurrentTime.jspx tutorial example. Converted Servlet class shows that action 'include' element is processed differently than directive 'include' elements by the Tomcat server.

After deploy those JSP Documents presented in the previous tutorial, I tried to visit the main JSP Document with a browser at: http://localhost:8080/CurrentTime.jspx. I got the following output:

Current time in different time zones:
America/New_York: 7:35 PM
America/Los_Angeles: 4:35 PM
Asia/Shanghai: 7:35 AM
Europe/Paris: 12:35 AM
Europe/Moscow: 3:35 AM

Current JVM:
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.vm.version: 10.0.1+10
os.name: Windows 7
os.version: 6.1

Current Time: 19:35:06 EDT 2018

If I visit the first include JSP Document with a browser at: http://localhost:8080/JvmStamp.jspx. I will get an invalid HTML page, but the page source is still a good XML document:

<b>Current JVM:</b><br/>java.vm.name: Java HotSpot(TM) 64-Bit Server VM<br/>
java.vm.version: 10.0.1+10<br/>
os.name: Windows 7<br/>
os.version: 6.1<br/>

If I visit the second include JSP Document with a browser at: http://localhost:8080/TimeStamp.jspx. I will get an invalid HTML page, but the page source is still a good XML document:

<b>Current Time: </b>19:36:05 EDT 2018

Now you want to see the Servlet class code converted from the main JSP Document, CurrentTime.jspx, here it is:

/*
 * 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.*;
import java.util.*;
import java.text.*;

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

   private Date now;
   private JspWriter out;
   private void printTime(String tz) throws Throwable {
      DateFormat df = DateFormat.getInstance();
      df.setTimeZone(TimeZone.getTimeZone(tz));
      out.println(tz+": "+df.format(now)+"<br/>");
   }

  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;

  static {
    _jspx_dependants
       = new java.util.HashMap<java.lang.String,java.lang.Long>(1);
    _jspx_dependants.put("/JvmStamp.jspx",
       Long.valueOf(1351726198882L));
  }

  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;charset=UTF-8");
      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>");
      out.write("<body>");
      out.write("<p>");
      out.write("<b>");
      out.write("Current time in different time zones:");
      out.write("</b>");
      out.write("<br/>");

   this.out = out;
   now = new Date();
   printTime("America/New_York");
   printTime("America/Los_Angeles");
   printTime("Asia/Shanghai");
   printTime("Europe/Paris");
   printTime("Europe/Moscow");

      out.write("</p>");
      out.write("<p>");
      out.write("<b>");
      out.write("Current JVM:");
      out.write("</b>");
      out.write("<br/>");

   String s;
   s = "java.vm.name";
   out.println(s+": "+System.getProperty(s)+"<br/>");
   s = "java.vm.version";
   out.println(s+": "+System.getProperty(s)+"<br/>");
   s = "os.name";
   out.println(s+": "+System.getProperty(s)+"<br/>");
   s = "os.version";
   out.println(s+": "+System.getProperty(s)+"<br/>");

      out.write("</p>");
      out.write("<p>");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(
         request, response, "TimeStamp.jspx", out, false);
      out.write("</p>");
      out.write("</body>");
      out.write("</html>");
    } 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);
    }
  }
}

Notice that:

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

 Syntactic Elements of a JSP Page

 JSP Document - JSP Page in XML Format

 JSP Document - JSP Version Error

 Writing Scriptlet Element in XML Format

 Writing Directive Element in XML Format

 Writing Action Element in XML Format

 "include" Directive and Action Elements

Execution Result of CurrentTime.jspx

 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