The Servlets Technology Model
The Servlets Technology Model
The Servlets Technology Model
Model
Web Application
An application that is accessible
from the web.
Web application is built of web
components that perform specific
task and are able to expose their
functionality on web server.
Web Application and web
server
A web application reside in web application
server.
Also provides low level services, such as HTTP
protocol implementation and database
connection management.
HTTP protocol
It is request –response based stateless
protocol.
Client sends an HTTP request for a resource
and server returns an HTTP response with the
desired resource.
It is stateless because once server sends the
response it forgets about client.
Types of Request
HTTP GET
protected void doGet(HttpServletRequest
req, HttpServletResponse res) throws
ServletException, java.io.IOException { ... }
Called by the server to handle a GET
request.
An 240 characters can be sent to the
server with such a request.
.
Types Of HTTP Request
HTTP POST
protected void doPost(HttpServletRequest req,
Class Interface
javax.servlet.GenericServlet javax.servlet.ServletConfig
Interface
Class javax.io.Serializable
javax.servlet.HttpServlet
The javax.servlet Package (Contd.)
A brief description of the classes and interfaces are as
follows:
Class/Interface Description
Nameclass
HTTPServlet Provides a HTTP specific
implementation of the
Servlet interface.
init()
Request
Client service()
(Browser)
Response
destroy()
Life Cycle of Servlets
init method-The init method is called on a
servlet instance right after it has been
initialized
The method can be overridden in a subclass to
provide one-time initialization of the servlet.
If for some reason this initialization fails, you
should throw an UnavailableException.
Without init method servlet will not brought
int service.
Called only once.
Life Cycle of Servlets
service()-
Called each time when server receives request
for servlets.
Service method checks the HTTP request
type(GET,POST,PUT,DELETE etc.) and calls
doGet,doPost,doPut,doDelete as appropriate.
You can aso use service directly instead of
doGet() and doPost().
Advantages of using
doxxx() over service.
You can later add support for other HTTP
request method by adding doPut,doPost
perhaps in subclass.
You can add support for modification dates by
adding getLastModified method.
Destroy() method
To destroy servlet instance