running java servlet program using apache tomcat server- a layman approach
DESCRIPTION
RUNNING JAVA SERVLET PROGRAM USING APACHE TOMCAT SERVERHow to run a java servlet programTRANSCRIPT
RUNNING JAVA SERVLET PROGRAM USING APACHE TOMCAT SERVER- A LAYMAN APPROACH
-J.SHIVALKAR
STEP 1: Install Tomcat7
STEP 2: Create a java servlet program process.java
STEP 3: Save this process.java in any folder in any drive as you wish.
For eg I have chosen F drive and folder named myjava
Save that file “process.java” in that folder myjava
STEP 4: Open command prompt
Type F:
Then type cd myjava
Set path for java by copying the address location of bin folder under jdk.
STEP 5:
Compile the process.java,this step is very important
Syntax: javac –classpath “servlet-api.jar address location” filename.java
*Note: Be careful in leaving spaces as shown above otherwise the program wouldn’t get compiled
process.class file will automatically be generated after successful compilation of the program
STEP 6:
Go to Tomcat Installation Directory
STEP 7:
Go to webapps folder
STEP 8:
Double click that folder and create a folder named “sample” inside that.
STEP 9:
Create a folder named “WEB-INF” inside sample
STEP 10:
Create a file named web.xml by typing the coding in notepad and save the file as web.xml into the folder “WEB-INF” folder.
STEP 11:
Create three folders inside WEB-INF namely
1. classes
2. lib
3. src
As you can see the screenshot that I have created three folders in the “WEB-INF” folder.
Copy the process.class file under myjava folder and paste it into the classes folder that we have created.
Copy the servlet-api file as shown in the screenshot above into the lib folder we have created
An overview of what things each folder contains
STEP 12:
This is the final step
Open any browser Mozilla Firefox or Internet Explorer or Chrome or Opera
Type the URL
Syntax for the URL is
http://localhost:8080/sample/ javaprogramfilename
According to my example the URL is
http://localhost:8080/sample/process
OUTPUT: