SlideShare a Scribd company logo
Servlet in java , java servlet , servlet servlet and CGI, API
Submitted by
K.Priyadarsini
N.Pandimeena
V.Sarmila
IIM.SC(CS&IT)
Nadar saraswathi college of arts & science ,
Theni.
SERVLET:
 Servlets provide a component-based, platform-
independent method for building Web based applications,
without the performance limitations of CGI programs.
Servlets have access to the entire family of Java APIs,
including the JDBC API to access enterprise databases.
 Java Servlets are programs that run on a Web or
Application server and act as a middle layer between a
requests coming from a Web browser or other HTTP
client and databases or applications on the HTTP server.
Java Servlets often serve the same purpose as
programs implemented using the Common Gateway
Interface (CGI). But Servlets offer several advantages in
comparison with the CGI.
 Performance is significantly better.
 Servlets execute within the address space of a Web
server. It is not necessary to create a separate process to
handle each client request.
 Servlets are platform independent because they are
written in Java.
 Java security manager on the server enforces a set of
restrictions to protect the resources on a server machine.
So servlets are trusted.
Servlet interface between client and server:
CGI(Common Gateway Interface):
CGI technology enables the web server to call
an external program and pass HTTP request information to
the external program to process the request. For each
request, it starts a new process.
Advantage of servlet:
 Better performance:
Because it creates a thread for each request not
process.
 Portability:
Because it uses java language.
 Robust:
Servlets are managed by JVM so we don't need
to worry about memory leak, garbage collection etc.
 Secure:
Because it uses java language..
Website:
 Website is a collection of related web pages that may
contain text, images, audio and video. The first page of a
website is called home page. Each website has specific
internet address (URL) that you need to enter in your
browser to access a website.
 Website is hosted on one or more servers and can be
accessed by visiting its homepage using a computer
network. A website is managed by its owner that can be an
individual, company or an organization.
HTTP:
 The Hypertext Transfer Protocol (HTTP) is
application-level protocol for collaborative, distributed,
hypermedia information systems. It is the data
communication protocol used to establish communication
between client and server.
 HTTP is TCP/IP based communication protocol,
which is used to deliver the data like image files, query
results, HTML files etc on the World Wide Web (WWW)
with the default port is TCP 80. It provides the
standardized way for computers to communicate with each
other.
The Basic Architecture of HTTP:
Servlet API:
 The javax.servlet and javax.servlet.http packages
represent interfaces and classes for servlet API.
 The javax.servlet package contains many interfaces
and classes that are used by the servlet or web container.
These are not specific to any protocol.
 The javax.servlet.http package contains interfaces
and classes that are responsible for http requests only.
javax.servlet:
The javax.servlet package contains a number of
classes and interfaces that describe and define the contracts
between a servlet class and the runtime environment
provided for an instance of such a class by a conforming
servlet container.
javax.servlet.http:
The javax.servlet.http package contains a
number of classes and interfaces that describe and define the
contracts between a servlet class running under the HTTP
protocol and the runtime environment provided for an
instance of such a class by a conforming servlet container.
Classes in javax.servlet package:
Generic Servlet
Servlet Input Stream
Servlet Output Stream
Servlet Request Wrapper
Servlet Response Wrapper
Servlet Request Event
Servlet Context Event
Servlet Request Attribute Event
Servlet Context Attribute Event
Servlet Exception
Unavailable Exception
Classes in javax.servlet.http package:
Http Servlet
Cookie
Http Servlet Request Wrapper
Http Servlet Response Wrapper
Http Session Event
Http Session Binding Event
Http Utils (deprecated now)
Http Servlet class:
 The Http Servlet class extends the Generic Servlet
class and implements Serializable interface. It provides
http specific methods such as doGet , doPost , doHead ,
doTrace etc.
Life Cycle of a Servlet (Servlet Life Cycle):
 The web container maintains the life cycle of a servlet
instance. Let's see the life cycle of the servlet:
Servlet class is loaded.
Servlet instance is created.
init method is invoked.
service method is invoked.
destroy method is invoked.
Diagram of servlet life cycle:
 As displayed in the above diagram, there are three
states of a servlet:
New
Ready
End
 The servlet is in new state if servlet instance is
created. After invoking the init() method, Servlet comes in
the ready state. In the ready state, servlet performs all the
tasks. When the web container invokes the destroy()
method, it shifts to the end state.
Written inside the public service method:
The public service method converts the Servlet
Request object into the Http Servlet Request type and Servlet
Response object into the Http Servlet Response type.
Then, calls the service method passing these
objects.
PROGRAM:
public void service(Servlet Request req , Servlet Response res)
throws Servlet Exception, IOException
{
Http Servlet Request request;
Http Servlet Response response;
try
{
request = (Http Servlet Request)req;
response = (Http Servlet Response)res;
}
catch(Class Cast Exception e)
{
throw new Servlet Exception("non HTTP request or response");
}
service(request, response);
}
Written inside the protected service method:
The protected service method checks the type
of request, if request type is get, it calls doGet method, if
request type is post, it calls doPost method, so on.
Let's see the internal code:
PROGRAM:
protected void service(HttpServletRequest req, HttpServlet
Response resp)
throws ServletException, IOException
{
String method = req . getMethod();
if(method . equals("GET"))
{
long lastModified = getLastModified(req);
if(lastModified == -1L)
{
}
....
}
}
Servlet in java , java servlet , servlet servlet and CGI, API

More Related Content

What's hot (20)

PPT
An Introduction To Java Web Technology
vikram singh
 
PPT
Listeners and filters in servlet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
PPTX
Servlet api & servlet http package
renukarenuka9
 
PPTX
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
PPT
Web Tech Java Servlet Update1
vikram singh
 
PPT
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
PPT
JAVA Servlets
deepak kumar
 
PPTX
Servlet.ppt
VMahesh5
 
PDF
Servlets
Ravi Kant Sahu
 
PPT
Java servlets
lopjuan
 
PPTX
Javax.servlet,http packages
vamsi krishna
 
PPTX
Servlets
Rajkiran Mummadi
 
PDF
Java EE 01-Servlets and Containers
Fernando Gil
 
PPT
Request dispatching in servlet
vikram singh
 
PPTX
J2ee servlet
vinoth ponnurangam
 
PPT
Java Servlet
Rajiv Gupta
 
PPT
Java Servlets
Nitin Pai
 
PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PPT
Servlet ppt by vikas jagtap
Vikas Jagtap
 
An Introduction To Java Web Technology
vikram singh
 
Listeners and filters in servlet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Servlet api & servlet http package
renukarenuka9
 
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
Web Tech Java Servlet Update1
vikram singh
 
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
JAVA Servlets
deepak kumar
 
Servlet.ppt
VMahesh5
 
Servlets
Ravi Kant Sahu
 
Java servlets
lopjuan
 
Javax.servlet,http packages
vamsi krishna
 
Java EE 01-Servlets and Containers
Fernando Gil
 
Request dispatching in servlet
vikram singh
 
J2ee servlet
vinoth ponnurangam
 
Java Servlet
Rajiv Gupta
 
Java Servlets
Nitin Pai
 
Java servlet life cycle - methods ppt
kamal kotecha
 
Servlet ppt by vikas jagtap
Vikas Jagtap
 

Similar to Servlet in java , java servlet , servlet servlet and CGI, API (20)

PPTX
UNIT-3 Servlet
ssbd6985
 
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
ssuser4f7d71
 
PPTX
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
PPT
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
tahirnaquash2
 
PPT
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
PPT
Servlet.ppt
MouDhara1
 
PPT
Servlet.ppt
kstalin2
 
PPT
Servlet1.ppt
KhushalChoudhary14
 
PPTX
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
PPT
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
shubhangimalas1
 
PPTX
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
PPTX
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
PDF
SERVER SIDE PROGRAMMING
Prabu U
 
PPTX
Servlets api overview
ramya marichamy
 
PPTX
Java servlets
yuvarani p
 
PPTX
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
VENKATESHBHAT25
 
PPTX
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
PPTX
Servlets
Akshay Ballarpure
 
PPTX
Wt unit 3
team11vgnt
 
PPT
Presentation on java servlets
Aamir Sohail
 
UNIT-3 Servlet
ssbd6985
 
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
ssuser4f7d71
 
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
tahirnaquash2
 
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
Servlet.ppt
MouDhara1
 
Servlet.ppt
kstalin2
 
Servlet1.ppt
KhushalChoudhary14
 
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
shubhangimalas1
 
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
SERVER SIDE PROGRAMMING
Prabu U
 
Servlets api overview
ramya marichamy
 
Java servlets
yuvarani p
 
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
VENKATESHBHAT25
 
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
Wt unit 3
team11vgnt
 
Presentation on java servlets
Aamir Sohail
 
Ad

Recently uploaded (20)

PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Ad

Servlet in java , java servlet , servlet servlet and CGI, API

  • 3. SERVLET:  Servlets provide a component-based, platform- independent method for building Web based applications, without the performance limitations of CGI programs. Servlets have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.  Java Servlets are programs that run on a Web or Application server and act as a middle layer between a requests coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
  • 4. Java Servlets often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But Servlets offer several advantages in comparison with the CGI.  Performance is significantly better.  Servlets execute within the address space of a Web server. It is not necessary to create a separate process to handle each client request.  Servlets are platform independent because they are written in Java.  Java security manager on the server enforces a set of restrictions to protect the resources on a server machine. So servlets are trusted.
  • 5. Servlet interface between client and server:
  • 6. CGI(Common Gateway Interface): CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request. For each request, it starts a new process.
  • 8.  Better performance: Because it creates a thread for each request not process.  Portability: Because it uses java language.  Robust: Servlets are managed by JVM so we don't need to worry about memory leak, garbage collection etc.  Secure: Because it uses java language..
  • 9. Website:  Website is a collection of related web pages that may contain text, images, audio and video. The first page of a website is called home page. Each website has specific internet address (URL) that you need to enter in your browser to access a website.  Website is hosted on one or more servers and can be accessed by visiting its homepage using a computer network. A website is managed by its owner that can be an individual, company or an organization.
  • 10. HTTP:  The Hypertext Transfer Protocol (HTTP) is application-level protocol for collaborative, distributed, hypermedia information systems. It is the data communication protocol used to establish communication between client and server.  HTTP is TCP/IP based communication protocol, which is used to deliver the data like image files, query results, HTML files etc on the World Wide Web (WWW) with the default port is TCP 80. It provides the standardized way for computers to communicate with each other.
  • 12. Servlet API:  The javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet API.  The javax.servlet package contains many interfaces and classes that are used by the servlet or web container. These are not specific to any protocol.  The javax.servlet.http package contains interfaces and classes that are responsible for http requests only.
  • 13. javax.servlet: The javax.servlet package contains a number of classes and interfaces that describe and define the contracts between a servlet class and the runtime environment provided for an instance of such a class by a conforming servlet container. javax.servlet.http: The javax.servlet.http package contains a number of classes and interfaces that describe and define the contracts between a servlet class running under the HTTP protocol and the runtime environment provided for an instance of such a class by a conforming servlet container.
  • 14. Classes in javax.servlet package: Generic Servlet Servlet Input Stream Servlet Output Stream Servlet Request Wrapper Servlet Response Wrapper Servlet Request Event Servlet Context Event Servlet Request Attribute Event Servlet Context Attribute Event Servlet Exception Unavailable Exception
  • 15. Classes in javax.servlet.http package: Http Servlet Cookie Http Servlet Request Wrapper Http Servlet Response Wrapper Http Session Event Http Session Binding Event Http Utils (deprecated now)
  • 16. Http Servlet class:  The Http Servlet class extends the Generic Servlet class and implements Serializable interface. It provides http specific methods such as doGet , doPost , doHead , doTrace etc.
  • 17. Life Cycle of a Servlet (Servlet Life Cycle):  The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet: Servlet class is loaded. Servlet instance is created. init method is invoked. service method is invoked. destroy method is invoked.
  • 18. Diagram of servlet life cycle:
  • 19.  As displayed in the above diagram, there are three states of a servlet: New Ready End  The servlet is in new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state. In the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it shifts to the end state.
  • 20. Written inside the public service method: The public service method converts the Servlet Request object into the Http Servlet Request type and Servlet Response object into the Http Servlet Response type. Then, calls the service method passing these objects.
  • 21. PROGRAM: public void service(Servlet Request req , Servlet Response res) throws Servlet Exception, IOException { Http Servlet Request request; Http Servlet Response response; try { request = (Http Servlet Request)req; response = (Http Servlet Response)res; } catch(Class Cast Exception e) { throw new Servlet Exception("non HTTP request or response"); } service(request, response); }
  • 22. Written inside the protected service method: The protected service method checks the type of request, if request type is get, it calls doGet method, if request type is post, it calls doPost method, so on. Let's see the internal code:
  • 23. PROGRAM: protected void service(HttpServletRequest req, HttpServlet Response resp) throws ServletException, IOException { String method = req . getMethod(); if(method . equals("GET")) { long lastModified = getLastModified(req); if(lastModified == -1L) { } .... } }