Servlet
Java Servlet is kind of java program that process and answer client request.It
is also java programming language class that used to extend capabilities of
server.
Here we are looking
for how to compile servlet program and execute it
Pr-requisite: Here we used
- jdk1.5.0_05,
- Tomcat 4.1,
- Servlet program Name: FirstServlet.java
- Program saved into below directory:
C:\Program
Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes\
Follow Instruction
below
Right click on your
My Computer icon of desktop.
Go to ->
Advanced Tab. -> Environmental variables
Click on that you
will find all the system variables lies over there.
In User Variables
section you can create environmental variables. Now click on new
1) Variable name: class path
value :<path
till lib of installed java>e.g.(C:\Program
Files\Java\jdk1.5.0\lib);.;<path till lib of tomcat> e.g.(C:\Program
Files\Apache Software Foundation\Tomcat 6.0\lib);<path till jsp-
api.jar>;<path till servlet-api.jar>e.g(C:\Program Files\Apache
Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache
Software Foundation\Tomcat 6.0\lib\jsp- api.jar);.;
CLASSPATH
C:\Program Files\Java\jdk1.5.0_05\lib;C:\Program Files\Apache Group\Tomcat 4.1\common\lib;C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar;
C:\Program Files\Java\jdk1.5.0_05\lib;C:\Program Files\Apache Group\Tomcat 4.1\common\lib;C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar;
2) Variable name: path
Value: <path
till bin of installed java>;<path till bin of tomcat> click ok to
create this variable.
PATH
C:\Program Files\Java\jdk1.5.0_05\bin;C:\Program Files\Apache Group\Tomcat 4.1\bin;
C:\Program Files\Java\jdk1.5.0_05\bin;C:\Program Files\Apache Group\Tomcat 4.1\bin;
3) Variable name: CATALINA_HOME
Value :< path till tomcat base>
e.g.(C:\Program Files\Apache Software Foundation\Tomcat 6.0)
CATALINA_HOME
C:\Program Files\Apache Group\Tomcat 4.1;C:\Program Files\Java\jdk1.5.0_05;
C:\Program Files\Apache Group\Tomcat 4.1;C:\Program Files\Java\jdk1.5.0_05;
4) Variable name: JAVA_HOME
Value : <path till java base> e.g.(C:\Program
Files\Java\jdk1.5.0)
JAVA_HOME
C:\Program Files\Java\jdk1.5.0_05
C:\Program Files\Java\jdk1.5.0_05
Then after,
Open command prompt,
Cd\
Cd C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes\
Compile your Servlet program,
javac FirstServlet.java
Start tomcat server,
Internet Explorer,.
http://localhost:8080/examples/servlet/FirstServlet
Cd C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes\
Compile your Servlet program,
javac FirstServlet.java
Start tomcat server,
Internet Explorer,.
http://localhost:8080/examples/servlet/FirstServlet
Your Output will
display
Tomcat 1.5 or higher
version
Compile the program
and place .class file into
C:\Program
Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-
examples\WEB-INF\classes this Directory.
Make Change into
web.xml file,
<servlet>
<servlet-name>Nameof Program</servlet-name> <servlet-class> Nameof Program </servlet-class> </servlet> <servlet-mapping>
<servlet-name> Nameof Program </servlet-name> <url-pattern>/servlet/ Nameof Program </url-pattern> </servlet-mapping> http://localhost:8080/servlets-examples/servlet/ Nameof Program
<servlet-name>Nameof Program</servlet-name> <servlet-class> Nameof Program </servlet-class> </servlet> <servlet-mapping>
<servlet-name> Nameof Program </servlet-name> <url-pattern>/servlet/ Nameof Program </url-pattern> </servlet-mapping> http://localhost:8080/servlets-examples/servlet/ Nameof Program
Your Output will
display....Thank You.