SlideShare a Scribd company logo
1 of 18
HTTP SERVLET CLASS
PRESENTED BY:
S.SABTHAMI
I.M.SC(IT)
NADAR SARASWATHI COLLEGE OF ARTS AND
SCIENCE
HTTP SERVLET METHODS
The HttpServlet class extends the
GenericServlet class and implements
Serializable interface. It provides http
specific methods such as doGet, doPost,
doHead, doTrace etc.
HTTP SERVLET
HTTP SERVLET METHODS
 public void service(ServletRequest
req,ServletResponse res)
dispatches the request to the protected service
method by converting the request and response
object into http type.
HTTP SERVLET METHODS
 protected void service(HttpServletRequest
req, HttpServletResponse res)
receives the request from the service method, and
dispatches the request to the doXXX() method
depending on the incoming http request type.
HTTP SERVLET METHODS
 protected void doGet(HttpServletRequest
req, HttpServletResponse res)
This method is called by servlet service
method to handle the HTTP GET request from
client. When overriding this method, read the
request data, write the response headers, get the
response’s writer or output stream object, and
finally, write the response data.
HTTP SERVLET METHODS
 protected void doPost(HttpServletRequest
req, HttpServletResponse res)
This method is called by servlet service method
to handle the POST request from client. The HTTP
POST method allows the client to send data of
unlimited length to the Web server a single time and
is useful when posting information to the server.
Unlike, doGet where we get information from the
sever this method is used when we are transferring
information from client to the server.
HTTP SERVLET
HTTP SERVLET METHODS
 protected void doHead(HttpServletRequest
req, HttpServletResponse res)
This method is called by servlet service method
to handle the HTTP HEAD request from client. The
client sends a HEAD request when it wants to see
only the headers of a response, such as Content-Type
or Content-Length
HTTP SERVLET METHODS
 protected void
doOptions(HttpServletRequest req,
HttpServletResponse res)
Called by the service method to allow a servlet to
handle a OPTIONS request. The OPTIONS request
determines which HTTP methods the server
supports and returns an appropriate header.
HTTP SERVLET METHODS
 protected void doPut(HttpServletRequest
req, HttpServletResponse res)
This method is called by servlet service
method to handle the PUT request from client. This
method is similar to doPost method but unlike
doPost method where we send information to the
server, this method sends file to the server, this is
similar to the FTP operation from client to server.
HTTP SERVLET METHODS
 protected void doTrace(HttpServletRequest
req, HttpServletResponse res)
This method is called by service() method for
handling TRACE request. Used for debugging
purposes.
HTTP SERVLET METHODS
 protected void doDelete(HttpServletRequest
req, HttpServletResponse res)
Called by servlet service() method to handle the
DELETE request from client that allows a client to
delete a document, webpage or information from the
server.
HTTP SERVLET METHODS
 protected long
getLastModified(HttpServletRequest req)
Returns a long integer specifying the time the
HttpServletRequest object was last modified, in
milliseconds since midnight, January 1, 1970 GMT,
or -1 if the time is not known
EXAMPLE PROGRAM
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Creating Http Servlet by Extending HttpServlet class
public class ExampleHttpServlet extends HttpServlet
{
private String mymsg;
public void init() throws ServletException
{
mymsg = "Http Servlet Demo";
}
EXAMPLE PROGRAM
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
{
// Setting up the content type of web page
response.setContentType("text/html");
// Writing the message on the web page
PrintWriter out = response.getWriter();
out.println("<h1>" + mymsg + "</h1>");
out.println("<p>" + "Hello Friends!" + "</p>");
}
EXAMPLE PROGRAM
public void destroy()
{
// Leaving empty. Use this if you want to perform
//something at the end of Servlet life cycle.
}
}
Java

More Related Content

Similar to Java

An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...WebStackAcademy
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5Adil Jafri
 
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 responsesbharathiv53
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2PawanMM
 
Sun certifiedwebcomponentdeveloperstudyguide
Sun certifiedwebcomponentdeveloperstudyguideSun certifiedwebcomponentdeveloperstudyguide
Sun certifiedwebcomponentdeveloperstudyguideAlberto Romero Jiménez
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restfulknight1128
 
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 KuteTushar B Kute
 

Similar to Java (20)

An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Servlets
ServletsServlets
Servlets
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5
 
Java servlets
Java servletsJava servlets
Java servlets
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
 
Servlet 03
Servlet 03Servlet 03
Servlet 03
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
servlet_lifecycle.pdf
servlet_lifecycle.pdfservlet_lifecycle.pdf
servlet_lifecycle.pdf
 
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
 
HTTP Basic
HTTP BasicHTTP Basic
HTTP Basic
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
Sun certifiedwebcomponentdeveloperstudyguide
Sun certifiedwebcomponentdeveloperstudyguideSun certifiedwebcomponentdeveloperstudyguide
Sun certifiedwebcomponentdeveloperstudyguide
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
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
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 

More from SabthamiS1

women%20empowerment11.pptx
women%20empowerment11.pptxwomen%20empowerment11.pptx
women%20empowerment11.pptxSabthamiS1
 
big data analytics.pptx
big data analytics.pptxbig data analytics.pptx
big data analytics.pptxSabthamiS1
 
Data minig.pptx
Data minig.pptxData minig.pptx
Data minig.pptxSabthamiS1
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptxSabthamiS1
 
distributed computing.pptx
distributed computing.pptxdistributed computing.pptx
distributed computing.pptxSabthamiS1
 
Network and internet security
Network and internet security Network and internet security
Network and internet security SabthamiS1
 
Advance computer architecture
Advance computer architecture Advance computer architecture
Advance computer architecture SabthamiS1
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithmSabthamiS1
 

More from SabthamiS1 (12)

women%20empowerment11.pptx
women%20empowerment11.pptxwomen%20empowerment11.pptx
women%20empowerment11.pptx
 
big data analytics.pptx
big data analytics.pptxbig data analytics.pptx
big data analytics.pptx
 
iot.pptx
iot.pptxiot.pptx
iot.pptx
 
dip.pptx
dip.pptxdip.pptx
dip.pptx
 
csc.pptx
csc.pptxcsc.pptx
csc.pptx
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Data minig.pptx
Data minig.pptxData minig.pptx
Data minig.pptx
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptx
 
distributed computing.pptx
distributed computing.pptxdistributed computing.pptx
distributed computing.pptx
 
Network and internet security
Network and internet security Network and internet security
Network and internet security
 
Advance computer architecture
Advance computer architecture Advance computer architecture
Advance computer architecture
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 

Recently uploaded

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Recently uploaded (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Java

  • 1. HTTP SERVLET CLASS PRESENTED BY: S.SABTHAMI I.M.SC(IT) NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE
  • 2. HTTP SERVLET METHODS The HttpServlet class extends the GenericServlet class and implements Serializable interface. It provides http specific methods such as doGet, doPost, doHead, doTrace etc.
  • 4. HTTP SERVLET METHODS  public void service(ServletRequest req,ServletResponse res) dispatches the request to the protected service method by converting the request and response object into http type.
  • 5. HTTP SERVLET METHODS  protected void service(HttpServletRequest req, HttpServletResponse res) receives the request from the service method, and dispatches the request to the doXXX() method depending on the incoming http request type.
  • 6. HTTP SERVLET METHODS  protected void doGet(HttpServletRequest req, HttpServletResponse res) This method is called by servlet service method to handle the HTTP GET request from client. When overriding this method, read the request data, write the response headers, get the response’s writer or output stream object, and finally, write the response data.
  • 7. HTTP SERVLET METHODS  protected void doPost(HttpServletRequest req, HttpServletResponse res) This method is called by servlet service method to handle the POST request from client. The HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is useful when posting information to the server. Unlike, doGet where we get information from the sever this method is used when we are transferring information from client to the server.
  • 9. HTTP SERVLET METHODS  protected void doHead(HttpServletRequest req, HttpServletResponse res) This method is called by servlet service method to handle the HTTP HEAD request from client. The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length
  • 10. HTTP SERVLET METHODS  protected void doOptions(HttpServletRequest req, HttpServletResponse res) Called by the service method to allow a servlet to handle a OPTIONS request. The OPTIONS request determines which HTTP methods the server supports and returns an appropriate header.
  • 11. HTTP SERVLET METHODS  protected void doPut(HttpServletRequest req, HttpServletResponse res) This method is called by servlet service method to handle the PUT request from client. This method is similar to doPost method but unlike doPost method where we send information to the server, this method sends file to the server, this is similar to the FTP operation from client to server.
  • 12. HTTP SERVLET METHODS  protected void doTrace(HttpServletRequest req, HttpServletResponse res) This method is called by service() method for handling TRACE request. Used for debugging purposes.
  • 13. HTTP SERVLET METHODS  protected void doDelete(HttpServletRequest req, HttpServletResponse res) Called by servlet service() method to handle the DELETE request from client that allows a client to delete a document, webpage or information from the server.
  • 14. HTTP SERVLET METHODS  protected long getLastModified(HttpServletRequest req) Returns a long integer specifying the time the HttpServletRequest object was last modified, in milliseconds since midnight, January 1, 1970 GMT, or -1 if the time is not known
  • 15. EXAMPLE PROGRAM import java.io.*; import javax.servlet.*; import javax.servlet.http.*; // Creating Http Servlet by Extending HttpServlet class public class ExampleHttpServlet extends HttpServlet { private String mymsg; public void init() throws ServletException { mymsg = "Http Servlet Demo"; }
  • 16. EXAMPLE PROGRAM public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Setting up the content type of web page response.setContentType("text/html"); // Writing the message on the web page PrintWriter out = response.getWriter(); out.println("<h1>" + mymsg + "</h1>"); out.println("<p>" + "Hello Friends!" + "</p>"); }
  • 17. EXAMPLE PROGRAM public void destroy() { // Leaving empty. Use this if you want to perform //something at the end of Servlet life cycle. } }