








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Web Design & Development CS-
Web Design & Development CS-
Lecture 26
Servlets are java technology’s answer to CGI programming. CGI was widely used for generating dynamic content before Servlets arrived. They were programs written mostly in C,C++ that run on a web server and used to build web pages.
As you can see in the figure below, a client sends a request to web server, server forwards that request to a servlet, servlet generates dynamic content, mostly in the form of HTML pages, and returns it back to the server, which sends it back to the client. Hence we can say that servlet is extending the functionality of the webserver (The job of the earlier servers was to respond only to request, by may be sending the required html file back to the client, and generally no processing was performed on the server)
— Servlets can do anything that a java class can do. For example, connecting with database, reading/writing data to/from file etc.
— Handles requests sent by the user (clients) and generates response dynamically (normally HTML pages).
— The dynamically generated content is send back to the user through a webserver (client)
Request
Response
JVM
Extends the functionality of the server by generating HTML pages dynamically
Request
Response
Web Design & Development CS-
Jakarta is an Apache project and tomcat is one of its subprojects. Apache Tomcat is an open source web server, which is used as an official reference implementation of Java Servlets and Java Server Pages technologies.
Tomcat is developed in an open and participatory environment and released under the Apache software license
To work with servlets and JSP technologies, you first need to set up the environment. Tomcat installation can be performed in two different ways (a) using .zip file (b) using .exe file. This setup process is broken down into the following steps:
Web Design & Development CS-
Let’s take a detail look on each step and get some hands on experience of environment setup.
1. Download the Apache Tomcat Server
From the http://tomcat.apache.org, download the zip file for the current release (e.g. jakarta-tomcat-5.5.9.zip or any latest version) on your C:\ drive. There are different releases available on site. Select to download .zip file from the Binary Distributions Æ core section.
Note: J2SE 5.0 must be installed prior to use the 5.5.9 version of tomcat.
2. Installing Tomcat using .zip file
Note: After extraction , make sure C:\jakarta-tomcat-5.5.9 contains a bin subdirectory. Sometimes students create their own directory and unzip the file there such as C:\jakarta-tomcat-5.5.9\jakarta-tomcat-5.5.9.This causes problems while giving path information
3. Set the JAVA_HOME variable
— JAVA_HOME indicates the root directory of your jdk. Set the JAVA_HOME environment variable to tell Tomcat, where to find java
Web Design & Development CS-
— Create a new User variable by clicking New button as shown above, the New User Variable window will appear — Set name of variable JAVA_HOME — The value is the installation directory of JDK (for example C:\Program Files\j2sdk_nb\j2sdk1.4.2). This is shown below in the picture. Please note that bin folder is not included in the path.
— Press Ok button to finish
Web Design & Development CS-
4. Set the CATALINA_HOME variable
CATALINA_HOME is used to tell the system about the root directory of the TOMCAT. There are various files (classes, exe etc) needed by the system to run. CATALINA_HOME is used to tell your system (in this case your web server Tomcat) where the required files are.
— To Set the CATALINA_HOME environment variable, create another User Variable.
— Type CATALINA_HOME as the name of the environment variable.
— Its value should be the path till your top-level Tomcat directory. If you have unzipped the Tomcat in C drive. It should be C:\jakarta-tomcat-5.5.9. This is shown below:
— Press Ok button to finish
variables and these are JAVA_HOME & CATALINA_HOME
5. Set the CLASSPATH variable
Since servlets and JSP are not part of the Java 2 platform, standard edition, you have to identify the servlet classes to the compiler. The server already knows about the servlet classes, but the compiler (i.e., javac) you use for compiling source files of servlet does not. So if you don't set your CLASSPATH, any attempt to compile servlets, tag libraries, or other classes that use the servlet API will fail with error messages about unknown classes.
— To Set the CLASSPATH environment variable, create another User Variable.
— Type CLASSPATH as the name of the environment variable.
— Its value should be the path for servlet-api.jar and jsp-api.jar. These file can be found on following path:
Web Design & Development CS-
Web Design & Development CS-
There is another easier way to carry out the environment setup using .exe file. However, it is strongly recommended that you must complete the environment setup using .zip file to know the essential fundamentals.
Let’s look at the steps involved to accomplish the environment setup using .exe file.
1. Download the Apache Tomcat Server
From the http://tomcat.apache.org, download the .exe file for the current release (e.g. jakarta-tomcat-5.5.9.zip) on your C:\ drive. There are different releases available on site. Select to download Windows executable (.exe) file from Binary Distributions Æ Core section.
Note: J2SE 5.0 must be installed to use the 5.5.9 version of tomcat.
2. Installing Tomcat using .exe file - Run the .exe file by double clicking on it. - Moving forward in setup, you will reach to the following window
Web Design & Development CS-
Choosing .exe mode does not require completing this step.
4. Set the CATALINA_HOME variable
Choosing .exe mode does not require completing this step.
5. Set the CLASSPATH variable
Same as step 5 of .zip installation mode
Web Design & Development CS-
6. Test the server
If tomcat installation is made using .exe file, follow these steps
Note: If default page doesn’t displayed, open up an internet explorer window, move on to Tools Æ Internet Options Æ Connections ÆLAN Settings. Make sure that option of “Bypass proxy server for local addresses” is unchecked.