JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
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 implementing the javax.servlet.jsp.HttpJspPage interface.
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); ... } }
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
►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
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Overview of JSTL (JSP Standard Tag Libraries)
Multiple Tags Working Together
Using Tomcat on CentOS Systems
Connecting to SQL Server from Servlet