");
pera ‘am enjoying this Servlet Application"); i
Out.printin(*
See You laterl
");
out. printla(""
out.printin(**);
}
}
Program Explanation :
* ‘Inthe above program, we have imported following files, :
import java.io.*;
import javax.serviet,*;
import javax.serviet.http.*;
Out of these files java.io package is useful for taking care of I/O operations.
The javax.servlet and javax.servlet-http are important Packages containing the classes and interfaces
that are required for the operation of servlets, The most commonly used interface from javax.servle!
Package is Servlet, Similarly most commonly used class in this Package is GenericServlet. The
ServletRequest and ServletResponse are another two commonly used interfaces defined in
Parameters. The commonly uy;
ServletException,
* The MIME type is specified as using the setCoritent ,
for the HTTP response to type tn ie madthon ee TyPe() method, This method sets the content typ?
that the browser should interpret the ‘contents as cette as the MIME type. This means
¥ le,How to execute Serviet program?
Step 1: Compile the above program using the javac command at command prompt.
Di\test>javac FirstServiet java
The class file for this program gets generated.
Step2 : Before running any serviet program, itis necessary to have
1. JDK installed .
2. Tomcat installed.
3. Class path for above two packages must be set,
For Tomcat installation, I prefer to install the package XAMPP. The XAMP contains a directory for
‘tomcat. The XAMPP package contains Apache Web server, MySQL,.PHP and Perl support. It can work
on both Windows and Linux operating System.
Step 3: Copy the class file generated in Step 1 to the path
C : \xampp\tomcat\webapps\examples\WEB-INF\classes
Step 4: Goto the directory
C: \xampp\tomcet\webapps\examples\WEB-INF
Open web.xml file and edit it as follows
FirstServiet FirstServiet
FirstServlet /servlet/ FirstServiet
= ° ae .
er a is popularly known as deployment descriptor. This is basically the configuration file
wel
that describes how to map the URL of web application to servlet.
Internal alias NameAdvanced Jaoa Programming
FirstServiet Es
FirstServlet
External alias Name
/serviet/ FirstServlet °
The Servlet comes with two alias names, internal and external. The internal name is used by the Tomcat
and the external name is given (to be written in