SlideShare ist ein Scribd-Unternehmen logo
1 von 34
U18CSI6201
INTERNET & WEB PROGRAMMING
SERVLETS
V.SENTHIL KUMAR
Department of CSE
COURSE
OUTCOMES
CO1: DESIGN A WEBSITE USING HTML (K5, S3)
CO2: Apply Cascading Style Sheet to design a HTML
Webpage (K3, S2)
CO3: Develop a HTML form and validate it using Java
Script (K5, S2)
CO4: Develop web application using JSP, Servlet (K5,
S3)
CO5: Develop an XML document and validate it using
SCHEMA (K5, S2)
AGENDA
WHAT IS
SERVLET?
ADVANTAGES SERVLET
ARCHITECTURE
SERVLET TASKS SERVLET
PACKAGE
SERVLET LIFE
CYCLE
What are
Servlets?
• Java Servlets are programs that
run on a Web or Application
server.
• 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.
• Implemented using the Common
Gateway Interface (CGI).
Servlet
CGI
(Common
Gateway
Interface)
Disadvantages of
CGI
• There are many problems in CGI technology:
1.If the number of clients increases, it takes
more time for sending the response.
2.For each request, it starts a process, and the
web server is limited to start processes.
3.It uses platform dependent language
e.g. C, C++, perl.
Advantages
of Servlet
Advantages
of servlet
Better performance: because it creates
a thread for each request, not process.
Portability: because it uses Java
language.
Robust: JVM manages Servlets, so we
don't need to worry about the memory
leak, garbage collection, etc.
Secure: because it uses java language.
Servlets
offer several
advantages
• Performance is significantly better.
• Servlets execute within the address
space of a Web server.
• Servlets are platform-independent
• Java security manager on the server
enforces a set of restrictions to protect
the resources on a server machine.
• The full functionality of the Java class
libraries is available to a servlet.
Servlets
Architecture
Servlet Container
• It provides the runtime environment for JavaEE
(j2ee) applications.
• The client/user can request only a static
WebPages from the server. If the user wants to
read the web pages as per input then the
servlet container is used in java.
Servlet
Container
Servlet
Container
States
Standalone: It is typical Java-based servers in which the
servlet container and the web servers are the integral
part of a single program. For example:- Tomcat running
by itself
In-process: It is separated from the web server, because
a different program runs within the address space of the
main server as a plug-in. For example:- Tomcat running
inside the JBoss.
Out-of-process: The web server and servlet container
are different programs which are run in a different
process. For performing the communications between
them, web server uses the plug-in provided by the
servlet container.
Server: Web vs.
Application
• Server is a device or a computer program that
accepts and responds to the request made by
other program, known as client. It is used to
manage the network resources and for running
the program or software that provides services.
• There are two types of servers:
1.Web Server
2.Application Server
Web
Server
Web server contains only web or servlet container. It can be used for
servlet, jsp, struts, jsf etc. It can't be used for EJB.
It is a computer where the web content can be stored. In general
web server can be used to host the web sites but there also used
some other web servers also such as FTP, email, storage, gaming etc.
Examples of Web Servers are: Apache Tomcat and Resin.
Generating response by using the script and communicating with
database.
Sending file to the client associated with the requested URL.
Web Server
Application
Server
• Application server contains Web and EJB containers.
It can be used for servlet, jsp, struts, jsf, ejb etc. It is a
component based product that lies in the middle-tier of
a server centric architecture.
• It provides the middleware services for state
maintenance and security, along with persistence and
data access. It is a type of server designed to install,
operate and host associated services and applications
for the IT services, end users and organizations.
Application
Server
Servlets Tasks
Read the explicit
data sent by the
clients (browsers).
1
Read the implicit
HTTP request data
sent by the clients
(browsers).
2
Process the data
and generate the
results.
3
Send the explicit
data (i.e., the
document) to the
clients (browsers).
4
Send the implicit
HTTP response to
the clients
(browsers).
5
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.
Interfaces in
javax.servlet
package
1.Servlet
2.ServletRequest
3.ServletResponse
4.RequestDispatcher
5.ServletConfig
6.ServletContext
7.SingleThreadModel
8.Filter
9.FilterConfig
10.FilterChain
11.ServletRequestListener
12.ServletRequestAttributeListener
13.ServletContextListener
14.ServletContextAttributeListener
Classes in
javax.servle
t package
1.GenericServlet
2.ServletInputStream
3.ServletOutputStream
4.ServletRequestWrapper
5.ServletResponseWrapper
6.ServletRequestEvent
7.ServletContextEvent
8.ServletRequestAttributeEvent
9.ServletContextAttributeEvent
10.ServletException
11.UnavailableException
Interfaces in
javax.servlet.http
package
1.HttpServletRequest
2.HttpServletResponse
3.HttpSession
4.HttpSessionListener
5.HttpSessionAttributeListener
6.HttpSessionBindingListener
7.HttpSessionActivationListener
8.HttpSessionContext
Classes in
javax.servlet.http
package
1.HttpServlet
2.Cookie
3.HttpServletRequestWrapper
4.HttpServletResponseWrapper
5.HttpSessionEvent
6.HttpSessionBindingEvent
7.HttpUtils
Servlets -
Life Cycle
A servlet life cycle can be defined as the entire process from its
creation till the destruction. The following are the paths followed
by a servlet.
The servlet is initialized by calling the init() method.
The servlet calls service() method to process a client's request.
The servlet is terminated by calling the destroy() method.
Finally, servlet is garbage collected by the garbage collector of
the JVM.
The init() Method
• The init method is called only once. It is
called only when the servlet is created,
and not called for any user requests
afterwards. So, it is used for one-time
initializations, just as with the init method
of applets.
The service()
Method
• The service() method is the main method to perform
the actual task. The servlet container (i.e. web server)
calls the service() method to handle requests coming
from the client( browsers) and to write the formatted
response back to the client.
• The service() method checks the HTTP request type
(GET, POST, PUT, DELETE, etc.) and calls doGet,
doPost, doPut, doDelete, etc. methods as
appropriate.
doGet() &
doPost()
The destroy()
Method
• The destroy() method is called only once at the end of
the life cycle of a servlet.
• This method gives your servlet a chance to close
database connections, halt background threads, write
cookie lists or hit counts to disk, and perform other
such cleanup activities.
Architecture
Diagram
Architecture
First the HTTP requests
coming to the server are
delegated to the servlet
container.
1
The servlet container loads
the servlet before invoking
the service() method.
2
Then the servlet container
handles multiple requests
by spawning multiple
threads, each thread
executing the service()
method of a single instance
of the servlet.
3

Weitere ähnliche Inhalte

Ähnlich wie Servlet.pptx

Ähnlich wie Servlet.pptx (20)

Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Servlet classnotes
Servlet classnotesServlet classnotes
Servlet classnotes
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Presentation on java servlets
Presentation on java servletsPresentation on java servlets
Presentation on java servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlets api overview
Servlets api overviewServlets api overview
Servlets api overview
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Servlets
ServletsServlets
Servlets
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Servlets
ServletsServlets
Servlets
 
Servlets
ServletsServlets
Servlets
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Major project report
Major project reportMajor project report
Major project report
 

Kürzlich hochgeladen

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Kürzlich hochgeladen (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

Servlet.pptx