Professional Documents
Culture Documents
com
http://www.roseindia.net/
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/index.html
***********************************
•The objective of server side programs is to centrally manage all programs relating to a particular
application (e.g. Banking, Insurance, e-shopping, etc).
•Clients with bare minimum requirement (e.g. Pentium II, Windows XP Professional, MS Internet
Explorer and an internet connection) can experience the power and performance of a
Server (e.g. IBM Mainframe, Unix Server, etc) from a remote location without having to
compromise on security or speed.
•More importantly, server programs are not only portable but also possess the capability to
generate dynamic responses based on user’s request.
***********************************
•A servlet container is nothing but a compiled, executable program. The main function of the
container is to load, initialize and execute servlets
***********************************
•It is interesting to note here that the container and the objects in a container are multithreaded.
***********************************
•Servlets are server as well as platform-independent.
***********************************
•Servlets run entirely inside the Java Virtual Machine. Since the Servlet runs at server side so it
does not checks the browser for compatibility
***********************************
•Servlets uses the classes in the java packages javax.servlet and javax.servlet.http
***********************************
HTTP Servlet typically used to:
•Priovide dynamic content like getting the results of a database query and returning to the client.
•Process and/or store the data submitted by the HTML.
•Manage information about the state of a stateless HTTP. e.g. an online shopping car manages
request for multiple concurrent customers.
***********************************
Now lets see what a servlet container does for each HTTP request for a servlet, in general :
•The servlet container loads the servlet class and calls the init method of the servlet as soon as
the servlet is called for the first time.
•Then this container makes an instance of javax.servlet.ServletRequest and
javax.servlet.ServletResponse for each request.
•Then it passes the ServletRequest and ServletResponse objects by invoking the servlet's
service method.
•Finally, it calls the destroy method and unload the servlet class when the servlet class is to be
shut down.
***********************************
A Generic servlet contains the following five methods:
***********************************
Project--->WebContent--->WebINF--->web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>test.HelloServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/rupa</url-pattern>
</servlet-mapping>
</web-app>
***********************************
Project--->src---> HelloServ.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;