Threads and the Servlets Generated by JSPs

 

Introduction.  Whenever a JSP page is accessed on a server it either
  • initiates generation of a servlet and a thread for this invoking of the page
  • makes use of a new thread for this invoking of the page based on a servlet that is already running
    • the servlet that is developed and compiled through such uses may well stay as a class on the server for some time in order to save recompilation

As you can likely tell, this generally reduces the overhead on the server involved with running JSP pages when compared to other web-based scripting languages.  It also allows for some other capabilities such as making use of multiple threads within the processing.

Tomcat is really a servlet engine (and web server) and essentially just one level away from compiled/executable code.  It is still my understanding that another engine named Jasper is used to convert JSP pages into servlets which can then be run by Tomcat.  This approach is significantly more efficient than competitor's approaches.

Finding the Generated Servlets.  Unfortunately, finding the servlets generated by a JSP page on any given server is not necessarily easy.  It definitely took me some time to find them at jasperations.net.

Remember, in general on jasperations.net

  • HTML and JSP files should be put in either the htdocs directory or a subdirectory of htdocs

In order to make certain you aren't writing over each other's work I have created subdirectories in htdocs for all of our work.  This is illustrated in the following snapshot of CuteFTP.

 

 

I shouldn't need to remind you that you each have a subdirectory based on your last name, and my subdirectory is called examples.

After much searching I found the servlets that are generated by the JSP pages we access.  You need to do the following.

  • move up on level to the root directory for the web
  • move into the catalina directory
  • move into the temp subdirectory

Then you should see something like the following.

 

 

The servlets generated by accessing JSPs in your subdirectories of /htdocs will be in the corresponding subdirectories of catalina/temp.

When you move into your subdirectory you should see something like the following.

 

 

You should notice a lot of names that look familiar.  Notice how each of your JSP files has generated both a code file with the .java extension and a class file.  Notice how the names are

JSPname_jsp.java

and

JSPname_jsp.class

We will examine some of these in the next webpage.