Java Servlets_New1
Java Servlets_New1
WEB APPLICATIONS
INTRODUCTION TO WEB
► GET Request data is sent in header to the
server. POST data is sent in request body.
► Get request can send only limited amount of
data upto 1024 characters. POST method
Large amount of data can be sent.
► Get request is not secured because data is
exposed in URL Post request is secured
because data is not exposed in URL.
► Get should never be used when dealing with
sensitive data
HTTP requests
page
► init() :
⮚ The init method is called only once. It is
called only when the servlet is created,
and not called for any user requests.
⮚ This method allows the servlet to per
form any setup processing such as
opening files or establishing connections
to their servers. If a servlet has been
permanently installed in a server, it
loads when the server starts to run.
Methods used
► Service():
⮚ The service() method is the main method to perform
the actual task.
⮚ The service() method is the heart of the servlet.
Each request message from a client results in a single
call to the servlet’s service() method.
⮚ Each time the server receives a request for a servlet,
the server spawns a new thread and calls service.
The service() method checks the HTTP request type
(GET, POST, PUT, DELETE, etc.) and calls doGet,
doPost, doPut, doDelete, etc. methods as
appropriate.
► Service():
⮚ The service() method reads the request and
produces the response message from its two
parameters: A ServletRequest object with data
from the client. A ServletResponse represents the
servlet’s reply back to the client. The service()
method’s job is conceptually simple—it creates a
response for each client request sent to it from the
host server.
⮚ The servlet container calls the service() method to
handle requests coming from the client or browsers
and to write the formatted response back to the
client. The service() method checks the HTTP
request type such as GET, POST etc and calls
doGet, doPost etc.
Methods used