Converting JSP Pages with Scripting Elements

This section describes general rules on how a JSP page with static data and scripting elements gets converted into a Servlet class source code.

From previous sections, we have learned that a JSP will be converted into a Java Servlet class and get executed to generate the HTTP response.

We have also learned that Java code fragments can entered in JSP pages as scripting elements to generate dynamic data into the HTTP response.

Here are general rules on how a JSP page with static data and scripting elements gets converted into a Servlet class source code:

1. A single JSP page will be converted into a single new class that should be subclass of javax.servlet.http.HttpServlet and impleting the javax.servlet.jsp.HttpJspPage interace.

2. All static data will be converted as out.write("static_data") statements and placed inside the _jspService() method.

3. All scriptlets will be converted as is and placed inside the _jspService() method.

4. All expressions will be converted as out.print(expression) statements and placed inside the _jspService() method.

5. All scripting declarations will be converted as is and placed before the _jspService() method.

Roughly, the converted Servlet class will look like:

...
public class hello_jsp extends javax.servlet.http.HttpServlet
   implements javax.servlet.jsp.HttpJspPage {
   ...
   scripting_declaration
   scripting_declaration
   ...
   public void _jspService(...) {
      ...
      out.write("static_data");
      ...
      scriptlet or out.print(scripting_expression);
      ..
      out.write("static_data");
      ...
      scriptlet or out.print(scripting_expression);
      ...
  }
}

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 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

 Outdated Tutorials

 References

 PDF Printing Version