This workshop is for you, if you thinking:

  • My simple Java code has a main method. I have heard that JSPs and Servlets do not have main method. So, how does it work?
  • I've read a lot about web.xml, servlet callback methods, JSP implicit variables etc. But how to use them all to make it work together?

This workshop is not for you, if you are thinking:

  • How to write Java file and compile it?
  • I dont have any clue what JSP or Servlet is
  • What is a Application server?
  • Am an expert writing JSP and Servlets, lets see how others write them!

Requirement:
Create a simple web page which has two fields, first name and last name as input fields.

  • When both values are entered and submitted, 'Your Name is : <First Name> <Last name>' should be displayed.
  • When any one value is not entered, the web page should display, 'Please enter first name' or 'Please enter Last name' or both as per the entry made by the use

Here we go....

1. Installing an application server:
We will be using Tomcat Application server this example. Download and install Tomcat from the http://tomcat.apache.org/

For this example, we will be using Tomcat 6.x. The table below maps the Tomcat version with Servlet specification. Tomcat 6.x is based on Servlet 2.5 specification. Tomcat 6.x installation requires the existence of J2SE/JRE 1.5 or above.

 Servlet/JSP  Tomcat J2SE 
 2.5/2.1  6.0.16  1.5 or above
 2.4/2.0  5.5.26

 1.3 or above

 2.3/1.2  4.1.37  1.2 or above

Below are the easy steps which will guide you through the installation process in Windows environment.

  • Click Next on the first screen and accept the terms of agreement to proceed with the installation.

        Tomcat - Choose Components

  • In the Choose component screen (See the screenshot above), select 'Services' checkbox to enable Tomcat as Windows service. This is a nice feature to have. You may also want to select 'Examples', if you want to have some JSP/Servlet samples installed by default. Click Next to continue.

         Tomcat - Install Location

  • In the Choose Install Location screen (See the above screenshot), browse to the folder where you want Tomcat to be installed and click Next.

         Tomcat - Configuration

  • In the Configuration screen, select the port on which you want Tomcat should listen to. By default it will be 8080 and it can be left as it is, unless you have some other application already listening on this port. You may also want to provide a password for the admin user

        Tomcat - JVM

  • In the Java Virtual Machine screen, by default any SDK or JRE of 1.5 or above will be displayed. You will need to have either JRE 1.5 or higher or SDK 1.5 or higher for installing Tomcat 6.x. Click Next to begin the installation process.
  • Click the finish button to complete the installation process.
  • You can now test your installation by starting Tomcat and access the URL http://localhost:8080/ assuming that Tomcat is listening on port 8080.
  • Tomcat will be waiting there to congratulate you, on successful installation!

 

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.