SlideShare a Scribd company logo
Department of Computer Science
Govt Post Graduate College Dargai Malakand
Presenting By: Aamir SohailPresenting By: Aamir Sohail
Subject: Advance OOP(Java)Subject: Advance OOP(Java)
Java ServletsJava Servlets
Page  2
What are the java servlets?
OR
Servlets are java-based server side programs
Java Servlets are programs that run on a Web 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.
??
Page  3
Server…Server…
A server is a computer that responds to
requests from a client.
Typical requests: provide a web page, upload or download a file,
send email.
A client could be the browser or other software
making these requests
Typically, My little computer is the client, and
someone else’s big computer is the server
Page  4
Servlets…
Servlets are java-based server side programs
Servlets are Java technology’s answer to Common
Gateway Interface (CGI) programming.
They are programs that run on a Web server, acting
as a middle layer between a request coming from a
Web browser or other HTTP client and databases or
applications on the HTTP server.
Page  5
Servlets…Servlets…
Using Servlets, you can collect input from users
through web page forms, present records from a
database or another source, and create web pages
dynamically.
Java Servlets often serve the same purpose as
programs implemented using the Common Gateway
Interface (CGI).
If we have this
Why we need
Servlets????
Page  6
let me explain
Page  7
CGI…
CGI stands for “Common Gateway Interface”
Client sends a request to server
Server starts a CGI script
Script computes a result for server
Another client sends a request
CGI Creates a new procces
Server returns response to client
Page  8
Servlets…Servlets…
Client sends a request to
server
Server starts a servlet
Servlet computes a result
for server and does not quit
Another client sends a
request
Server calls the servlet
again
Etc.
Server returns response to
client
Page  9
Servlets vs. CGI scripts
Advantages:
Running a servlet doesn’t require creating a separate
process each time
A servlet stays in memory, so it doesn’t have to be
reloaded each time
There is only one instance handling multiple requests,
not a separate instance for every request
Page  10
The Advantages of Servlets Over “Traditional” CGI
Java servlets are more efficient,
easier to use,
more powerful,
more portable,
safer,
and cheaper than traditional CGI and many alternative CGI-like
technologies
Page  11
With traditional CGI, a new process is started for each
HTTP request. If the CGI program itself is relatively
short, the overhead of starting the process can dominate
the execution time.
With servlets, the Java virtual machine stays running and
handles each request with a lightweight Java thread, not a
heavyweight operating system process
Page  12
Similarly, in traditional CGI, if there are N requests to
the same CGI program, the code for the CGI program
is loaded into memory N times.
With servlets, however, there would be N threads, but
only a single copy of the servlet class would be loaded.
This approach reduces server memory requirements and
saves time by instantiating fewer objects
Page  13
The Servlet Life Cycle
In Slide 10 and 11 (The Advantages of Servlets Over
“Traditional” CGI), I referred to the fact that only a
single instance of a servlet gets created, with each
user request resulting in a new thread that is handed
off to doGet or doPost as appropriate.
I’ll now explain how servlets are created and
destroyed, and how and when the various methods are
invoked. I give a quick summary here, then elaborate in
the following subsections.
Page  14
After this, each user request results in a thread that
calls the service method of the previously created
instance.
Multiple concurrent requests normally result in multiple
threads calling service
The service method then calls doGet, doPost, or
another method, depending on the type of HTTP
request it received.
When the servlet is first created, its init method is
invoked, so init is where you put one-time setup code.
Page  15
Finally, when the server decides to unload a
servlet, it first calls the servlet’s destroy
method.
Page  16
The init Method…
The init method is called when the servlet is first created;
it is not called again for each user request. So, it is used
for one-time initializations.
The servlet is normally created when a user first invokes a
URL corresponding to the servlet, but you can also specify
that the servlet be loaded when the server is first started
Page  17
The service Method
Each time the server receives a request for a servlet, the
server spawns a new thread and calls service.
The service method checks the HTTP request type (GET,
POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut,
doDelete, etc
Page  18
Destroy Method
Called when server deletes servletinstance.
Not called after each request
Page  19
how to create servletshow to create servlets (Basic Structure)(Basic Structure)
Page  20
In the above program a basic servlet that handles
GET requests. GET requests, for those unfamiliar
with HTTP, are the usual type of browser requests
for Web pages.
A browser generates this request when the user
enters a URL on the address line, follows a link from
a Web page, or submits an HTML form that either
does not specify a METHOD or specifies
METHOD="GET".
Page  21
Servlets can also easily handle POST requests, which
are generated when someone submits an HTML form
that specifies METHOD="POST".
Page  22
Advantages of Servlets over other server side
technologies (ASP, CGI etc)
A servlet can be imagined to be as an applet
running on the server side. Some of the other
server side technologies available are Common
Gateway Interface (CGI), server side
JavaScript and Active Server Pages (ASP).
Advantages of servlets over these server
side technologies are as follows:
Page  23
Persistent
Servlets remain in memory until explicitly destroyed. This helps in
serving several incoming requests.
Servlets establishes connection only once with the database and can
handle several requests on the same database.
This reduces the time and resources required to establish connection
again
and again with the same database.
Whereas, CGI programs are removed from the memory once the request is
processed and each time a new process is initiated whenever new request
arrives.
Page  24
Portable
Since servlets are written in Java, they are portable.
That is, servlets are compatible with almost all operating systems.
The programs written on one operating system can be executed on
other operating system
Page  25
Server-independent
Servlets are compatible with any web server available today.
Most of the software vendors today support servlets within their
web server products.
On the other hand, some of the server side technologies like
server side JavaSricpt and ASP can run on only selected web
servers.
The CGI is compatible with the web server that has features to
supports it.
Page  26
Fast
Since servlets are compiled into bytecodes, they can
execute more quickly as compared to other scripting
languages. The bytecode compilation feature helps
servlets to give much better performance. In
addition, it also provides advantage of strong error
and type checking.
Page  27
How to run servlet?
There are Six Steps to Running Your First Servlet
 Create a directory structure under Tomcat for
your application.
 Write the servlet source code. You need to import
the javax.servlet package and the
javax.servlet.http package in your source file.
 Compile your source code.
 Create a deployment descriptor.
 Run Tomcat.
 Call your servlet from a web browser.
Page  28
Create a Directory Structure under Tomcat
 When you install Tomcat, several subdirectories are
automatically created under the Tomcat home directory
(%TOMCAT_HOME%). One of the subdirectories is webapps.
 The webapps directory is where you store your web applications.
A web application is a collection of servlets and other contents
installed under a specific subset of the server's URL
namespace.
 A separate directory is dedicated for each servlet application.
Therefore, the first thing to do when you build a servlet
application is create an application directory
Page  29
Compile Your Source Code
For your servlet source code to compile, you need to include in
your CLASSPATH environment variable the path to the
servlet.jar file. The servlet.
jar is located in the commonlib subdirectory under
%CATALINA_HOME%.
30
Thank You !!!
References:
Wikipedi.org
Videos on youtube
Askme.com
And some PDF files about Java Servlets.

More Related Content

What's hot

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
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
JeongHun Byeon
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
Ivano Malavolta
 
Servlet session 1
Servlet   session 1Servlet   session 1
Servlet session 1
Anuj Singh Rajput
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
Milan Thapa
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 Conference
Roger Kitain
 
Server side programming
Server side programming Server side programming
Server side programming
javed ahmed
 
Reverse proxy
Reverse proxyReverse proxy
Reverse proxy
Proxies Rent
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
Madhaiyan Muthu
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
webhostingguy
 
Java web application development
Java web application developmentJava web application development
Java web application development
RitikRathaur
 
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a CometDDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
Richard Banks
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
Arun Gupta
 
Overview of java web services
Overview of java web servicesOverview of java web services
zigbee
zigbeezigbee
Web servers
Web serversWeb servers
Web servers
webhostingguy
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
guest8899ec02
 
4 Basic PHP
4 Basic PHP4 Basic PHP
4 Basic PHP
Jalpesh Vasa
 
Web server
Web serverWeb server
Web server
Touhid Arastu
 

What's hot (20)

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
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
Servlet session 1
Servlet   session 1Servlet   session 1
Servlet session 1
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 Conference
 
Server side programming
Server side programming Server side programming
Server side programming
 
Reverse proxy
Reverse proxyReverse proxy
Reverse proxy
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a CometDDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
DDD Sydney 2011 - Getting out of Sync with IIS and Riding a Comet
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
zigbee
zigbeezigbee
zigbee
 
Web servers
Web serversWeb servers
Web servers
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
 
4 Basic PHP
4 Basic PHP4 Basic PHP
4 Basic PHP
 
Web server
Web serverWeb server
Web server
 

Similar to Presentation on java servlets

Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
Praveen Yadav
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
JAVA
JAVAJAVA
Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
Payal Dungarwal
 
Servlets
ServletsServlets
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
Senthil Kumar
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
SenthilKumar571813
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
Jafar Nesargi
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Ahmed Madkor
 
Servlet by Rj
Servlet by RjServlet by Rj
Major project report
Major project reportMajor project report
Major project report
Omprakash Dhakad
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
Siva Priya
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
 
Java servlets
Java servletsJava servlets
Java servlets
Mukesh Tekwani
 

Similar to Presentation on java servlets (20)

Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
JAVA
JAVAJAVA
JAVA
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
 
Servlets
ServletsServlets
Servlets
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Servlets
ServletsServlets
Servlets
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Major project report
Major project reportMajor project report
Major project report
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 

More from Aamir Sohail

Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
Aamir Sohail
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
Aamir Sohail
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
Aamir Sohail
 
Vb script
Vb scriptVb script
Vb script
Aamir Sohail
 
Infromation securiity
Infromation securiityInfromation securiity
Infromation securiity
Aamir Sohail
 
Network Security Policies
Network Security PoliciesNetwork Security Policies
Network Security Policies
Aamir Sohail
 
Scheduling and scheduling personnel
Scheduling and scheduling personnelScheduling and scheduling personnel
Scheduling and scheduling personnel
Aamir Sohail
 

More from Aamir Sohail (7)

Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
 
Vb script
Vb scriptVb script
Vb script
 
Infromation securiity
Infromation securiityInfromation securiity
Infromation securiity
 
Network Security Policies
Network Security PoliciesNetwork Security Policies
Network Security Policies
 
Scheduling and scheduling personnel
Scheduling and scheduling personnelScheduling and scheduling personnel
Scheduling and scheduling personnel
 

Recently uploaded

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 

Recently uploaded (20)

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 

Presentation on java servlets

  • 1. Department of Computer Science Govt Post Graduate College Dargai Malakand Presenting By: Aamir SohailPresenting By: Aamir Sohail Subject: Advance OOP(Java)Subject: Advance OOP(Java) Java ServletsJava Servlets
  • 2. Page  2 What are the java servlets? OR Servlets are java-based server side programs Java Servlets are programs that run on a Web 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. ??
  • 3. Page  3 Server…Server… A server is a computer that responds to requests from a client. Typical requests: provide a web page, upload or download a file, send email. A client could be the browser or other software making these requests Typically, My little computer is the client, and someone else’s big computer is the server
  • 4. Page  4 Servlets… Servlets are java-based server side programs Servlets are Java technology’s answer to Common Gateway Interface (CGI) programming. They are programs that run on a Web server, acting as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
  • 5. Page  5 Servlets…Servlets… Using Servlets, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically. Java Servlets often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). If we have this Why we need Servlets????
  • 6. Page  6 let me explain
  • 7. Page  7 CGI… CGI stands for “Common Gateway Interface” Client sends a request to server Server starts a CGI script Script computes a result for server Another client sends a request CGI Creates a new procces Server returns response to client
  • 8. Page  8 Servlets…Servlets… Client sends a request to server Server starts a servlet Servlet computes a result for server and does not quit Another client sends a request Server calls the servlet again Etc. Server returns response to client
  • 9. Page  9 Servlets vs. CGI scripts Advantages: Running a servlet doesn’t require creating a separate process each time A servlet stays in memory, so it doesn’t have to be reloaded each time There is only one instance handling multiple requests, not a separate instance for every request
  • 10. Page  10 The Advantages of Servlets Over “Traditional” CGI Java servlets are more efficient, easier to use, more powerful, more portable, safer, and cheaper than traditional CGI and many alternative CGI-like technologies
  • 11. Page  11 With traditional CGI, a new process is started for each HTTP request. If the CGI program itself is relatively short, the overhead of starting the process can dominate the execution time. With servlets, the Java virtual machine stays running and handles each request with a lightweight Java thread, not a heavyweight operating system process
  • 12. Page  12 Similarly, in traditional CGI, if there are N requests to the same CGI program, the code for the CGI program is loaded into memory N times. With servlets, however, there would be N threads, but only a single copy of the servlet class would be loaded. This approach reduces server memory requirements and saves time by instantiating fewer objects
  • 13. Page  13 The Servlet Life Cycle In Slide 10 and 11 (The Advantages of Servlets Over “Traditional” CGI), I referred to the fact that only a single instance of a servlet gets created, with each user request resulting in a new thread that is handed off to doGet or doPost as appropriate. I’ll now explain how servlets are created and destroyed, and how and when the various methods are invoked. I give a quick summary here, then elaborate in the following subsections.
  • 14. Page  14 After this, each user request results in a thread that calls the service method of the previously created instance. Multiple concurrent requests normally result in multiple threads calling service The service method then calls doGet, doPost, or another method, depending on the type of HTTP request it received. When the servlet is first created, its init method is invoked, so init is where you put one-time setup code.
  • 15. Page  15 Finally, when the server decides to unload a servlet, it first calls the servlet’s destroy method.
  • 16. Page  16 The init Method… The init method is called when the servlet is first created; it is not called again for each user request. So, it is used for one-time initializations. The servlet is normally created when a user first invokes a URL corresponding to the servlet, but you can also specify that the servlet be loaded when the server is first started
  • 17. Page  17 The service Method Each time the server receives a request for a servlet, the server spawns a new thread and calls service. The service method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc
  • 18. Page  18 Destroy Method Called when server deletes servletinstance. Not called after each request
  • 19. Page  19 how to create servletshow to create servlets (Basic Structure)(Basic Structure)
  • 20. Page  20 In the above program a basic servlet that handles GET requests. GET requests, for those unfamiliar with HTTP, are the usual type of browser requests for Web pages. A browser generates this request when the user enters a URL on the address line, follows a link from a Web page, or submits an HTML form that either does not specify a METHOD or specifies METHOD="GET".
  • 21. Page  21 Servlets can also easily handle POST requests, which are generated when someone submits an HTML form that specifies METHOD="POST".
  • 22. Page  22 Advantages of Servlets over other server side technologies (ASP, CGI etc) A servlet can be imagined to be as an applet running on the server side. Some of the other server side technologies available are Common Gateway Interface (CGI), server side JavaScript and Active Server Pages (ASP). Advantages of servlets over these server side technologies are as follows:
  • 23. Page  23 Persistent Servlets remain in memory until explicitly destroyed. This helps in serving several incoming requests. Servlets establishes connection only once with the database and can handle several requests on the same database. This reduces the time and resources required to establish connection again and again with the same database. Whereas, CGI programs are removed from the memory once the request is processed and each time a new process is initiated whenever new request arrives.
  • 24. Page  24 Portable Since servlets are written in Java, they are portable. That is, servlets are compatible with almost all operating systems. The programs written on one operating system can be executed on other operating system
  • 25. Page  25 Server-independent Servlets are compatible with any web server available today. Most of the software vendors today support servlets within their web server products. On the other hand, some of the server side technologies like server side JavaSricpt and ASP can run on only selected web servers. The CGI is compatible with the web server that has features to supports it.
  • 26. Page  26 Fast Since servlets are compiled into bytecodes, they can execute more quickly as compared to other scripting languages. The bytecode compilation feature helps servlets to give much better performance. In addition, it also provides advantage of strong error and type checking.
  • 27. Page  27 How to run servlet? There are Six Steps to Running Your First Servlet  Create a directory structure under Tomcat for your application.  Write the servlet source code. You need to import the javax.servlet package and the javax.servlet.http package in your source file.  Compile your source code.  Create a deployment descriptor.  Run Tomcat.  Call your servlet from a web browser.
  • 28. Page  28 Create a Directory Structure under Tomcat  When you install Tomcat, several subdirectories are automatically created under the Tomcat home directory (%TOMCAT_HOME%). One of the subdirectories is webapps.  The webapps directory is where you store your web applications. A web application is a collection of servlets and other contents installed under a specific subset of the server's URL namespace.  A separate directory is dedicated for each servlet application. Therefore, the first thing to do when you build a servlet application is create an application directory
  • 29. Page  29 Compile Your Source Code For your servlet source code to compile, you need to include in your CLASSPATH environment variable the path to the servlet.jar file. The servlet. jar is located in the commonlib subdirectory under %CATALINA_HOME%.
  • 30. 30 Thank You !!! References: Wikipedi.org Videos on youtube Askme.com And some PDF files about Java Servlets.