Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA SERVLET

Compiling and Running a Simple Servlet

 Compile the Source File

First you have to include some lines into your Autoexec.bat files. These are

set CLASSPATH = C:\JSDK2.0\LIB;C:\JSDK2.0\LIB\JSDK.JAR;

path = c:\jsdk2.0\bin;c:\jsdk2.0\lib;

Compile the source file using the Java compiler.

If the compilation succeeds, the compiler creates a file named First_Serv.class in the same directory (folder) as the Java source file (First_Serv.java). This class file contains Java bytecodes.

C:/>JAVAC First_Serv.java

Running A Servlet

Calling Servlets From a Browser 

Once you have written your servlet, you can test it with the utility included in the JSDK. The JSDK 2.0 has a utility called servletrunner (c:\jsdk2.0\bin\servletrunner.exe), while JSDK 2.1 comes with a small HTTP server.  

First run the utility called servletrunner

Then the URL for a servlet has the following general form, where servlet-name corresponds to the name you have given your servlet: 

http://machine-name:port/servlet/servlet-name

Example :-  

http://localhost:8080/servlet/First_Serv


Previous

Next