Install Tomcat server of your choice version by downloading from Apache site. Many versions of Tomcat can be found in the following link.
Check with the documentation of what JDK or JRE version is compatible to the specific Tomcat version. For example I have loaded Tomcat 5.0 and is compatible with JDK 6.0.
While installation, it asks the port number and I have entered 8888 (default is displayed as 8080. I have not preferred 8080 for the reason on many systems Oracle server will be working on 8080. For this reason better choose a different port number). Later, give your own password.
JSP in Tomcat Execution Step-by-Step
Step 1:When installed, Tomcat gives many folders of which a few are given hereunder used for execution. See the following one.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;
Keep the above JAR file in the classpath of Windows Environment Variables and also keep in the same classpath tools.jar that comes with JDK installation. tools.jar is not necessary for Servlets, but required for JSPs. servlet-api.jar is required for both Servlets and JSPs.
Note: Now, a fresher should be careful here in the following steps. Steps are very simple but should be followed carefully. Any small mistake committed, Tomcat simply refuses to execute your JSP.
Step 2: Creating your own directory structure.
You also get the following folders.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps
In the above webapps folder create your own new folder. I created and named it as "india".
Step 3: Observe the following directory structure.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF
Just copy the above WEB-INF folder (ofcourse, along with its subdirectories) into india folder.
When you did, now you get the following structure. Check it.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\india\WEB-INF
Note 1: Do not confuse now with the WEB-INF folder as WEB-INF exists in two places – one in ROOT (ROOT is predefined) and one in india (india you have created).
Note 2: Tomcat is case-sensitive. Do not write web-inf instead of WEB-INF etc.
Remember, now onwards when I talk about WEB-INF folder, I mean the WEB-INF available in india and not in ROOT. This is very important.
Step 4: Deploying JSP file.
Copy the JSP files and HTML files from your own folder to india folder. This is called deployment (copying JSP file to Tomcat folder).
Step 5: Execute the client HTML file
a) you must have deployed JSP file (or you get 404 error) and then
b) write in HTML file <form method="get" action="http://localhost:8888/india/Validation.jsp">
Now the client HTML file calls Validation.jsp available on Tomcat. You get the output in the browser.
Step 6: Writing alias name (<url-pattern>) of JSP in web.xml
Coming to Servlets, giving alias name is mandatory but in JSP it is optional. To make coding simple, in many examples I am not writing alias name for JSPs and writing directly JSP file name in the action attribute of <form> tag. One example is shown how to give alias name to JSP file in Mapping JSP file in web.xml file with alias name