SlideShare a Scribd company logo
Objectives In this lesson, you will learn to: Identify the characteristics of a Servlet Create a Servlet  Deploy a Servlet
Need for Servlets Servlets are required to: Reduce the overhead on the server and network To take care of processing data on the Web server
Servlets are: Java programs that can be deployed on a Java enabled Web server  Used to extend the functionality of a Web server Used to add dynamic content to Web pages
Characteristics of Servlets Servlets are: Efficient Initialization code for a servlet is executed only once  Robust Provide all powerful features of Java
Portable across Web servers Persistent Increase the performance of a system by preventing frequent disk access
Comparison between Servlets and Applets Applets: Are embedded in Web pages  Require the browser to be Java-enabled Take a lot of time to be downloaded
Servlets: Execute on the Web server, thus help overcome problems with download time Do not require the browser to be Java-enabled
Comparison between Servlets and other Server- Side Scripting Technologies Common Gateway Interface (CGI) scripts, JSP, and ASP are alternatives to servlets CGI Scripts: Are programs written in C, C++, or Perl Get executed in a server Run in separate processes for each client access Require the interpreter to be loaded on the server A JSP file is automatically converted to a servlet  before it is executed
Comparison between Servlets and other Server- Side Scriptings Active Server Pages (ASP): Is a server-side scripting language developed by Microsoft Enables a developer to combine HTML and a scripting language in the same Web page   Are not compatible with all Web servers
Working of Servlets Client browser passes requests to a servlet using the following methods: GET Uses a query string to send additional information to the server Query string is displayed in the client browser
POST Sends the data as packets to the server through a separate socket connection  Complete transaction is invisible to the client Slower compared to the GET method
The  javax.servlet  Package Hierarchy of classes that are used to create a servlet Class java.lang.Object Class  javax.servlet.GenericServlet Class  javax.servlet.HttpServlet Interface  javax.servlet.Servlet Interface  javax.servlet.ServletConfig Interface javax.io.Serializable
The  javax.servlet  Package (Contd.) A brief description of the classes and interfaces Provides methods to process requests from the clients. HTTPServletRequest  interface Provides a HTTP specific implementation of the  Servlet  interface.  HTTPServlet  class Description Class/Interface
Response to the client is sent in the form of a HTML page through an object of the  HTTPServletResponse  class. HTTPServlet Response   interface Used to store the servlets startup configuration values and the initialization parameters. ServletConfig   class
Life Cycle of a Servlet Life cycle of a servlet: Client (Browser) init() service() destroy() Request Response
Life Cycle of a Servlet (Contd.) The following table describes few methods that are used in creating a servlet:  Receives all requests from clients, identifies the type of the request, and dispatches them to the  doGet()  or  doPost()  methods for processing.  Servlet. service() Contains all initialization code for the servlet. Servlet.init (ServletConfig config) throws ServletException Functionality Method name
Life Cycle of a Servlet (Contd.) Executes only once when the servlet is removed from server.  Servlet. destroy() Sets the type of content that is to be sent as response to the client browser.  HTTPServlet Response. setContentType (String type) Returns a reference to a  PrintWriter  object.  HTTPServlet Response. getWriter() Functionality Method name
Deploying a Servlet A servlet can be deployed in: Java Web Server (JWS) JRun Apache Java 2 Enterprise Edition (J2EE) server
Identify the mechanism to record the number of hits on a Web site Client browsers that are used to access the Web site  run on different machines Hence, the client (browser) cannot keep track of the hit count data This data has to be captured on the server’s side Thus, a technique that can be used to write a server-side program is necessary to solve this problem
Identify the classes to be used   A class that extends the  HttpServlet  class must be coded to solve the problem
Identify the methods to be used  The  init()  method needs to be coded in the  hitcountServlet  class to initialize the hitcounter to zero   The  doGet()  method needs to be coded to increment  the hit counter whenever a client browser makes a  request for the site home page
Write and compile the servlet Set the values of  PATH  and  CLASSPATH  variables Code the servlet program Compile the program by using the command  javac hitcountServlet.java
Execute the servlet Type  http://127.0.0.1:8000/hitcountwebcontext/hitcounter   in the address bar of the browser to execute the servlet
Problem for you….   In the URL that is provided, identify the Web context name and the alias name of the servlet http://127.0.0.1:8000/name/execute
Summary In this lesson, you learned that: Servlets are server-side Java programs that can be deployed on a Web Server  The Servlet interface provides the basic framework for coding servlets
Servlets are : Portable Extensible  Persistent  Robust
Summary (Contd.) The life cycle of a servlet is composed of the  init() ,  service() , and the  destroy()  methods  Servlets can be deployed in the J2EE server and JWS  The  deploytool  command is used to deploy a servlet on a J2EE server
Ad

More Related Content

What's hot (20)

Servlets
ServletsServlets
Servlets
Rajkiran Mummadi
 
Core web application development
Core web application developmentCore web application development
Core web application development
Bahaa Farouk
 
Servlet lifecycle
Servlet lifecycleServlet lifecycle
Servlet lifecycle
Durga Devi Thulluri
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
Servlet
Servlet Servlet
Servlet
Dhara Joshi
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
Minal Maniar
 
Introduction to Servlets
Introduction to ServletsIntroduction to Servlets
Introduction to Servlets
Fulvio Corno
 
Servlets
ServletsServlets
Servlets
Sasidhar Kothuru
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
vikram singh
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
Kumar
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
Web Developer Tools
Web Developer ToolsWeb Developer Tools
Web Developer Tools
Mindfire Solutions
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
Gary Yeh
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Rami Nayan
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
Ahmed Assaf
 
Rack
RackRack
Rack
Aakanksha Bhardwaj
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
Venkateswara Rao N
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh
 
Core web application development
Core web application developmentCore web application development
Core web application development
Bahaa Farouk
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
Minal Maniar
 
Introduction to Servlets
Introduction to ServletsIntroduction to Servlets
Introduction to Servlets
Fulvio Corno
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
vikram singh
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
Kumar
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
Gary Yeh
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Rami Nayan
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
Ahmed Assaf
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh
 

Similar to Servlet 01 (20)

Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
SERVLET in web technolgy engineering.pptx
SERVLET in web technolgy engineering.pptxSERVLET in web technolgy engineering.pptx
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
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
PRIYADARSINISK
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
Lokesh Singrol
 
Java servlets
Java servletsJava servlets
Java servlets
yuvarani p
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
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
Tushar B Kute
 
Major project report
Major project reportMajor project report
Major project report
Omprakash Dhakad
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
Praveen Yadav
 
J servlets
J servletsJ servlets
J servlets
reddivarihareesh
 
SERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servletsSERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptxUnitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
VikasTuwar1
 
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
bharathiv53
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
Manjunatha RK
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
SachinSingh217687
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
SERVLET in web technolgy engineering.pptx
SERVLET in web technolgy engineering.pptxSERVLET in web technolgy engineering.pptx
SERVLET in web technolgy engineering.pptx
ARUNKUMARM230658
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
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
PRIYADARSINISK
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
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
Tushar B Kute
 
SERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servletsSERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptxUnitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
Unitwwsbdsbsdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-4.pptx
VikasTuwar1
 
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
bharathiv53
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Ad

Recently uploaded (20)

HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Ad

Servlet 01

  • 1. Objectives In this lesson, you will learn to: Identify the characteristics of a Servlet Create a Servlet Deploy a Servlet
  • 2. Need for Servlets Servlets are required to: Reduce the overhead on the server and network To take care of processing data on the Web server
  • 3. Servlets are: Java programs that can be deployed on a Java enabled Web server Used to extend the functionality of a Web server Used to add dynamic content to Web pages
  • 4. Characteristics of Servlets Servlets are: Efficient Initialization code for a servlet is executed only once Robust Provide all powerful features of Java
  • 5. Portable across Web servers Persistent Increase the performance of a system by preventing frequent disk access
  • 6. Comparison between Servlets and Applets Applets: Are embedded in Web pages Require the browser to be Java-enabled Take a lot of time to be downloaded
  • 7. Servlets: Execute on the Web server, thus help overcome problems with download time Do not require the browser to be Java-enabled
  • 8. Comparison between Servlets and other Server- Side Scripting Technologies Common Gateway Interface (CGI) scripts, JSP, and ASP are alternatives to servlets CGI Scripts: Are programs written in C, C++, or Perl Get executed in a server Run in separate processes for each client access Require the interpreter to be loaded on the server A JSP file is automatically converted to a servlet before it is executed
  • 9. Comparison between Servlets and other Server- Side Scriptings Active Server Pages (ASP): Is a server-side scripting language developed by Microsoft Enables a developer to combine HTML and a scripting language in the same Web page Are not compatible with all Web servers
  • 10. Working of Servlets Client browser passes requests to a servlet using the following methods: GET Uses a query string to send additional information to the server Query string is displayed in the client browser
  • 11. POST Sends the data as packets to the server through a separate socket connection Complete transaction is invisible to the client Slower compared to the GET method
  • 12. The javax.servlet Package Hierarchy of classes that are used to create a servlet Class java.lang.Object Class javax.servlet.GenericServlet Class javax.servlet.HttpServlet Interface javax.servlet.Servlet Interface javax.servlet.ServletConfig Interface javax.io.Serializable
  • 13. The javax.servlet Package (Contd.) A brief description of the classes and interfaces Provides methods to process requests from the clients. HTTPServletRequest interface Provides a HTTP specific implementation of the Servlet interface. HTTPServlet class Description Class/Interface
  • 14. Response to the client is sent in the form of a HTML page through an object of the HTTPServletResponse class. HTTPServlet Response interface Used to store the servlets startup configuration values and the initialization parameters. ServletConfig class
  • 15. Life Cycle of a Servlet Life cycle of a servlet: Client (Browser) init() service() destroy() Request Response
  • 16. Life Cycle of a Servlet (Contd.) The following table describes few methods that are used in creating a servlet: Receives all requests from clients, identifies the type of the request, and dispatches them to the doGet() or doPost() methods for processing. Servlet. service() Contains all initialization code for the servlet. Servlet.init (ServletConfig config) throws ServletException Functionality Method name
  • 17. Life Cycle of a Servlet (Contd.) Executes only once when the servlet is removed from server. Servlet. destroy() Sets the type of content that is to be sent as response to the client browser. HTTPServlet Response. setContentType (String type) Returns a reference to a PrintWriter object. HTTPServlet Response. getWriter() Functionality Method name
  • 18. Deploying a Servlet A servlet can be deployed in: Java Web Server (JWS) JRun Apache Java 2 Enterprise Edition (J2EE) server
  • 19. Identify the mechanism to record the number of hits on a Web site Client browsers that are used to access the Web site run on different machines Hence, the client (browser) cannot keep track of the hit count data This data has to be captured on the server’s side Thus, a technique that can be used to write a server-side program is necessary to solve this problem
  • 20. Identify the classes to be used A class that extends the HttpServlet class must be coded to solve the problem
  • 21. Identify the methods to be used The init() method needs to be coded in the hitcountServlet class to initialize the hitcounter to zero The doGet() method needs to be coded to increment the hit counter whenever a client browser makes a request for the site home page
  • 22. Write and compile the servlet Set the values of PATH and CLASSPATH variables Code the servlet program Compile the program by using the command javac hitcountServlet.java
  • 23. Execute the servlet Type http://127.0.0.1:8000/hitcountwebcontext/hitcounter in the address bar of the browser to execute the servlet
  • 24. Problem for you…. In the URL that is provided, identify the Web context name and the alias name of the servlet http://127.0.0.1:8000/name/execute
  • 25. Summary In this lesson, you learned that: Servlets are server-side Java programs that can be deployed on a Web Server The Servlet interface provides the basic framework for coding servlets
  • 26. Servlets are : Portable Extensible Persistent Robust
  • 27. Summary (Contd.) The life cycle of a servlet is composed of the init() , service() , and the destroy() methods Servlets can be deployed in the J2EE server and JWS The deploytool command is used to deploy a servlet on a J2EE server