You are on page 1of 9

Java Servlets

Introduction to Web
Client request contains URL
Of the resource the client is
Looking for
Request

Client Server

Response

Server’s response contain the


Actual page the client requested
HTTP (Hypertext Transfer Protocol)
• HTTP is a protocol that clients and servers use on the web to communicate.
• HTTP is a stateless protocol i.e HTTP supports only one request per
connection. This means that with HTTP the clients connect to the server
to send one request and then disconnects. This mechanism allows more
users to connect to a given server over a period of time.
• The client sends an HTTP request and the server answers with an HTML
page to the client, using HTTP.
HTTP Methods
• OPTIONS: Request for communication options that are available on the
request/response chain.
• GET: Request to retrieve information from server using a given URI.
• POST: Request for server to accept the entity enclosed in the body of
HTTP method.
Difference Between GET and POST
GET Request POST Request
Data is sent in header to the server Data is sent in the request body
Get request can send only limited amount Large amount of data can be sent.
of data
Get request is not secured because data is Post request is secured because data is
exposed in URL not exposed in URL.
Get request can be bookmarked and is Post request cannot be bookmarked.
more efficient.
Introduction to Servlet
• Servlet Technology is used to create web applications.
• Servlet technology uses Java language to create web
applications.

Communicate

Request
Web Browser Servlet
Web
(Client) (Web App)
Server
Response

Dynamic
Page
Advantages of Servlet
• Less response time because each request runs in a separate
thread
• Servlets are robust and object oriented.
• Servlets are scalable.
• Servlets are platform independent.
Servlet Life Cycle

Initialization Service Destruction


init() service() destroy()

Request Response
Servlet Life Cycle
1. Loading of Servlet
2. Creating Instance of Servlet
3. Invoke init() method
4. Invoke service() method
5. Invoke destroy() method

You might also like