SlideShare a Scribd company logo
1 of 28
BY
Vijayapriya P
I M.Sc., CS
servletA servlet is a java programming
language
Class that is used to extend the capabilities
of
Servers.
 That host applications accessed by means
Of a request-response programming
model.
Although servlets can respond to any type
Of request, they are commonly used to
Life cycle of a servlet
Three methods are central to the
Life cycle of a servlet.these are
 Init()
 Service()
 Destroy()
They are implemented by every servlet
And are invoked at specific times by
The server.
oTwo packages contain the classes and
interfaces that are required to build
servlets.
javax.servlet
javax.servlet.http
 The javax.servlet package contains a
number of interfaces and classes that
establish the framework in which servlets
operate.
 Servlet  Declares life cycle methods
for a servlet.
 ServletConfig  Allows servlets to get
initialization parameters.
 ServletContext  Enables servlets to
log events and access information
about their
environment.
 ServletRequest  Used to read data
from a client request.
 ServletResponse  Used to write data
to a client response.
 The following items summarizes the
core classes that are provided in the
javax.servlet
 GenericServlet Implements the
Servlet and ServletConfig interfaces.
 ServletInputStream Provides an
input stream for reading requests
from a client.
 ServletOutputStream  Provides an
output stream for writing responses to
a client.
 ServletException  Indicates a
servlet error occurred.
 UnavailableException  Indicates a
servlet is unavailable.
The javax.servlet.http package contains a
number of interfaces and classes
 HttpServletRequest  Enables servlets to
read data from an HTTP request.
 HttpServletResponse  Enables servlets to
write data to an HTTP response.
 HttpSession  Allows session data to
be read and written.
 HttpSessionBindingListener 
Informs an object that it is bound to
or unbound from a session.
 The servlet is invoked when a form on a web
page is submitted. The example contains
three files as summarized here:
 AddCookie htm Allows a user to specify a
value for the cookie named MyCookie.
 AddCookieServlet java Processes the
submission of AddCookie.htm.
 GetCookiesServlet java Displays cookie
values.
 HTTP is a stateless protocol. Each request is
independent of the previous one.
 However, insome applications, it is necessary to
save state information so that information can
be collected from several interactions between
a browser and a server. Sessions provide such a
mechanism.
 A session can be created via the getSession( )
method of HttpServletRequest. An
 HttpSession object is returned. This object can
store a set of bindings that associate names
with objects.
 setAttribute( )
 getAttribute( )
 getAttributeNames( )
 removeAttribute( )
Package create
Create servlet
Simple servlet program
Package com.priya.demo;
Import java.io.IOexception;
Import java.io.servletexception;
Import jvax.servlet.servletexception;
Import javax.servlet.http.httpservlet;
Import java.servlet.http.httpservletrequest;
Import java.servlet.http.httpservletresponse;
Public class helloservlet extends httpservlet
{
private state final long serialversionUID=1l;
Public helloservlet()
{
Super();
Servlet program:
Protected void doget(httpservletrequest,httpservletresponse)
Throws servletexception,Ioexception
{
Response.setconteenttype(“texthtml”);
System.out.println(“<html><body>”);
System.out.println(“hello user…current date and time is:”);
Date d=new date();
System.out.println(“</body></html>”);
}
{
}
Run the program
output
Thank you

More Related Content

What's hot

Soap web service
Soap web serviceSoap web service
Soap web serviceNITT, KAMK
 
INTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project reportINTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project reportKULDEEPSINGH CHAUHAN
 
Exchange 2013 Architecture Poster
Exchange 2013 Architecture PosterExchange 2013 Architecture Poster
Exchange 2013 Architecture PosterRian Yulian
 
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...Exchange of data over internet using web service(e.g., soap and rest) in SAS ...
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...Kevin Lee
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web servicesNeil Ghosh
 
Mule digital signature processor
Mule digital signature processorMule digital signature processor
Mule digital signature processorKrishna_in
 
Web Services
Web ServicesWeb Services
Web ServicesF K
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Martin Necasky
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET Journal
 
Mail server using Linux(Ubuntu)
Mail server using Linux(Ubuntu)Mail server using Linux(Ubuntu)
Mail server using Linux(Ubuntu)Navjot Navi
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedPort80 Software
 
Application layer protocol
Application layer protocolApplication layer protocol
Application layer protocolTom Hanstead
 

What's hot (20)

Soap web service
Soap web serviceSoap web service
Soap web service
 
INTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project reportINTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project report
 
Web Services in the Real World
Web Services in the Real WorldWeb Services in the Real World
Web Services in the Real World
 
Exchange 2013 Architecture Poster
Exchange 2013 Architecture PosterExchange 2013 Architecture Poster
Exchange 2013 Architecture Poster
 
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...Exchange of data over internet using web service(e.g., soap and rest) in SAS ...
Exchange of data over internet using web service(e.g., soap and rest) in SAS ...
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Mule digital signature processor
Mule digital signature processorMule digital signature processor
Mule digital signature processor
 
Internet mail server
Internet mail server Internet mail server
Internet mail server
 
Web Services
Web ServicesWeb Services
Web Services
 
Mail server
Mail serverMail server
Mail server
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Web service architecture
Web service architectureWeb service architecture
Web service architecture
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)
 
Webservices
WebservicesWebservices
Webservices
 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
 
Mail server using Linux(Ubuntu)
Mail server using Linux(Ubuntu)Mail server using Linux(Ubuntu)
Mail server using Linux(Ubuntu)
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting Started
 
WSDL 2.0 and Apache Woden
WSDL 2.0 and Apache WodenWSDL 2.0 and Apache Woden
WSDL 2.0 and Apache Woden
 
Application layer protocol
Application layer protocolApplication layer protocol
Application layer protocol
 

Similar to Java servlets

Similar to Java servlets (20)

TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
 
Servlet 01
Servlet 01Servlet 01
Servlet 01
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Servlets
ServletsServlets
Servlets
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4
 
Servlet
Servlet Servlet
Servlet
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Weblogic
WeblogicWeblogic
Weblogic
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T S
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMING
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Java servlets

  • 2. servletA servlet is a java programming language Class that is used to extend the capabilities of Servers.  That host applications accessed by means Of a request-response programming model. Although servlets can respond to any type Of request, they are commonly used to
  • 3.
  • 4.
  • 5. Life cycle of a servlet Three methods are central to the Life cycle of a servlet.these are  Init()  Service()  Destroy() They are implemented by every servlet And are invoked at specific times by The server.
  • 6.
  • 7. oTwo packages contain the classes and interfaces that are required to build servlets. javax.servlet javax.servlet.http
  • 8.  The javax.servlet package contains a number of interfaces and classes that establish the framework in which servlets operate.  Servlet  Declares life cycle methods for a servlet.  ServletConfig  Allows servlets to get initialization parameters.
  • 9.  ServletContext  Enables servlets to log events and access information about their environment.  ServletRequest  Used to read data from a client request.  ServletResponse  Used to write data to a client response.
  • 10.  The following items summarizes the core classes that are provided in the javax.servlet  GenericServlet Implements the Servlet and ServletConfig interfaces.  ServletInputStream Provides an input stream for reading requests from a client.
  • 11.  ServletOutputStream  Provides an output stream for writing responses to a client.  ServletException  Indicates a servlet error occurred.  UnavailableException  Indicates a servlet is unavailable.
  • 12. The javax.servlet.http package contains a number of interfaces and classes  HttpServletRequest  Enables servlets to read data from an HTTP request.  HttpServletResponse  Enables servlets to write data to an HTTP response.
  • 13.  HttpSession  Allows session data to be read and written.  HttpSessionBindingListener  Informs an object that it is bound to or unbound from a session.
  • 14.  The servlet is invoked when a form on a web page is submitted. The example contains three files as summarized here:  AddCookie htm Allows a user to specify a value for the cookie named MyCookie.  AddCookieServlet java Processes the submission of AddCookie.htm.  GetCookiesServlet java Displays cookie values.
  • 15.  HTTP is a stateless protocol. Each request is independent of the previous one.  However, insome applications, it is necessary to save state information so that information can be collected from several interactions between a browser and a server. Sessions provide such a mechanism.
  • 16.  A session can be created via the getSession( ) method of HttpServletRequest. An  HttpSession object is returned. This object can store a set of bindings that associate names with objects.  setAttribute( )  getAttribute( )  getAttributeNames( )  removeAttribute( )
  • 17.
  • 18.
  • 21.
  • 23. Package com.priya.demo; Import java.io.IOexception; Import java.io.servletexception; Import jvax.servlet.servletexception; Import javax.servlet.http.httpservlet; Import java.servlet.http.httpservletrequest; Import java.servlet.http.httpservletresponse; Public class helloservlet extends httpservlet { private state final long serialversionUID=1l; Public helloservlet() { Super(); Servlet program:
  • 24. Protected void doget(httpservletrequest,httpservletresponse) Throws servletexception,Ioexception { Response.setconteenttype(“texthtml”); System.out.println(“<html><body>”); System.out.println(“hello user…current date and time is:”); Date d=new date(); System.out.println(“</body></html>”); } { }
  • 26.