The Servlets Generated by JSPs
Introduction.
Now we need to examine servlets just a bit so we can start to become
familiar with them. We will do this by working through two of the
simplest JSP pages we have done so far.
I find it a very intriguing experience to see what servlet code is generated even by simple JSP pages! At present you need to make sure you have uploaded hello_world.jsp and cubes.jsp to your jasperations.net directory /htdocs/yourLastName and then execute them. Now you need to go to /catalina/temp/yourLastName and download
so you can view them. These servlets can also be useful in debugging since it is often the case that the line numbers displayed in error reports correspond to line numbers in these servlets! I will try to place the source JSP and generated servlets side-by-side to assist comparison. |
Original hello_world.jsp | Generated Servlet Code for hello_world_jsp.java |
<html> <head> <title>Hello World JSP Page</title> </head> <body> <% out.println("<H1>Hello World</H1>"); %> </body> </html> |
package
org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.jasper.runtime.*; public class hello_world_jsp extends HttpJspBase {
} |
I rest my case for not taking the usual academic
approach and digging into servlets in order to do JSPs! Though, I must acknowledge, this particular servlet engine is unusually cryptic. The following is the code for the cubes.jsp and associated generated servlet. |
Original cubes.jsp | Generated Servlet Code for cubes_jsp.java |
<html> <head> <title>Calculating Cubes</title> </head> <body bgcolor = "000044" text="cccccc"> <% out.println("<h2><B>Cubes</B></h2><BR>"); int iLoop; int iCube; for (iLoop = 1; iLoop <= 10; iLoop++) {
} |
package
org.apache.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.jasper.runtime.*; public class cubes_jsp extends HttpJspBase {
} |
We will endeavor to discuss these in class! |