Setting up a Servlet development environment
This tutorial provides step by step instructions to setup the development environment required to test various servlet examples given throughout all the tutorials. This tutorial will also be helpful when you start practicing servlets yourself.
List of required softwares:
- JAVA 1.5 or 1.6
- Tomcat 5.5.16
- eclipse 3.3
Note: this tutorial explains how to install required software on your windows based PC only.
First of all you need the Java software development kit 1.5 or 1.6 (JAVA SDK) installed.
Checking if JAVA is already installed in your system
Follow this step to check if Java software development kit (JDK) is already installed in your system.
To determine if JAVA SDK is already installed in your system, run the following command from command prompt.
Java –version
If JAVA platform is already installed, it will display the version of the JAVA SDK. Below screen shows JAVA version 1.6 running on a windows system. If command executes successfully and shows JAVA version 1.6, you can skip the next step.otherwise download and install the Java SDK as explained in next step.
Install JAVA SDK
First thing you need to install is Java software development kit (Java SDK) .Download the Java development kit 6 (JDK 6) from Sun Java SE Download site. Current latest version is JDK 6 update 6.
Set up the JAVA_HOME environment variable
Once the JAVA SDK is installed follow this step to set the JAVA_HOME environment variable. If JAVA_HOME variable is already set, you can skip this step.
Right click on My Computer icon on your desktop it will open a popup menu, click on properties, it will open the system properties window, then click on advanced tab.
Click on environment variables button, it will open the environment variables window as shown in figure below. Initially there will be no JAVA_HOME environment variable set as shown in figure.
Click on new button to add new system variable JAVA_HOME.
In the variable name filed, enter JAVA_HOME. Specify the path to root directory of JAVA installation in variable value field and click OK button. Now JAVA_HOME will appear under user variables.
Next you need to add bin directory under the root directory of JAVA installation in PATH environment variable.Select the PATH variable from System variables and click on Edit button.
Add: ;%JAVA_HOME%\bin; at the end of variable value field and click OK button.
Now verify that everything is correct by following the step: Checking if JAVA is already installed in your system. It should show the version of the installed JAVA SDK.
Installing Tomcat
Tomcat is an opensource web container. it is also web container reference implementation. You will need tomcat 5.5.16 installed on your system to test various servlet and JSP examples given in other tutorials.
Download the latest version of tomcat from this URL
Note: This directory is referred as TOMCAT_HOME in other tutorials.
That’s all, tomcat is installed. It’s very easy, isn’t it?
Starting and shutting down Tomcat
To start the tomcat server, open the command prompt, change the directory to TOMCAT HOME/bin and run the startup.bat file. It will start the server.
>startup
To shut down the tomcat server, run the shutdown.bat file. It will stop the server.
>shutdown
Verifying Tomcat installation
To verify that tomcat is installed properly, start the server as explained above, open the web browser and access the following URL.
http://localhost:8080/index.jsp
It should show the tomcat welcome page, if tomcat is installed properly and server is running.
Setting up the CLASSPATH
Now you need to create a new environment variable CLASSPATH if it is not already set. We need to add the servlet-api.jar into the CLASSPATH to compile the Servlets. Follow the same steps as you did to create the JAVA_HOME variable. Create a new variable CLASSPATH under system variables. Add TOMCAT_HOME/lib/servlet-api.jar in variable value field.
Note: here TOMCAT_HOME refers to the tomcat installation directory.
