21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d...
-
Upload
dustin-mccormick -
Category
Documents
-
view
214 -
download
0
Transcript of 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d...
![Page 1: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/1.jpg)
22/04/23 1
SSSSSS
Java ServletsJava Servlets
By,
Kshirsagar Harshada Mangesh.
Third Year Computer
Government Polytechnic, Pune.
![Page 2: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/2.jpg)
22/04/23 2
What are Servlets?
What are Servlets?
Why are
Servlets?
Why are
Servlets?
How are Servlets?How are Servlets?
Why not CGI?Why not CGI?
When are
Servlets?
When are
Servlets?
Where are
Servlets?
Where are
Servlets?
Some Questions In your Mind…. Servlets
Kshirsagar Harshada Mangesh
![Page 3: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/3.jpg)
22/04/23 3
Concepts
Internet : network of networks
WWW (World Wide Web) also referred to as web :
- One of the largest Internet services - Consists of millions of websites
![Page 4: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/4.jpg)
22/04/23 4
How web works
Web Browser
WebServer
URLBrowser requests
A web page
WebServer sends backthe requested page
Uniform Resource Locator which specifies the location of the webpage on the webserver
http://www.rediff.com/index.html
Stores the WebPages & sends themto the browser upon a request
![Page 5: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/5.jpg)
22/04/23 5
Serving static HTML page
WebServer
Browser requestsA web page
WebServer sends backthe requested page
Initially web servers were designed to provide the static WebPages
HTMLpage
WebPagesOn
Hard Disk
![Page 6: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/6.jpg)
22/04/23 6
Servlets
Kshirsagar Harshada Mangesh
![Page 7: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/7.jpg)
22/04/23 7
Servlets
Kshirsagar Harshada Mangesh
![Page 8: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/8.jpg)
22/04/23 8
Servlets
Kshirsagar Harshada Mangesh
![Page 9: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/9.jpg)
22/04/23 9
Servlets
Kshirsagar Harshada Mangesh
![Page 10: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/10.jpg)
22/04/23 10
![Page 11: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/11.jpg)
22/04/23 11
![Page 12: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/12.jpg)
22/04/23 12
![Page 13: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/13.jpg)
22/04/23 13
![Page 14: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/14.jpg)
22/04/23 14
a soultion for dynamically generating HTML
• Servlets are small platform-independent server-side programs that extend the functionality of a webserver
• It is a java class which run on the webserver and communicate with the web browser using HTML & HTTP
• A no of servlets can form a website.
Servlets
Kshirsagar Harshada Mangesh
![Page 15: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/15.jpg)
22/04/23 15
But web consists of millions of websites( comprising of billions of webpages linked together using hyperlinks)
So there require someone to host these websites & map web applications to servlets.
This task of hosting servlets & web applications is done by
Servlets
Kshirsagar Harshada Mangesh
![Page 16: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/16.jpg)
22/04/23 16
Architecture of a Servlet (Request-Response Flow)
WebBrowser
WebServer
HTTPRequest
HTTPResponse
Mappinginformation
Web Application
WebContainer
Staticresources
Servlets
Static resources
![Page 17: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/17.jpg)
22/04/23 17
init() destroy()Servlet
3 distinct phasesBirthLifeDeath
service()
![Page 18: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/18.jpg)
22/04/23 18
init() method
• called before the servlet handles its first request• The container passes ServletConfig Object contaning the
initialization parameters to this method• If overridden must call super.init() first
public void init(ServletConfig config)throws SerletException
{
}
![Page 19: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/19.jpg)
22/04/23 19
service() method
• Each time the server receives a request for a servlet,it spawns a new thread & calls the service method
• It is the entry point for executing application logic in a servlet
WebServer
Browser
Browser
Browser
service()
service()
service()
SingleInstance
Of theservlet
public void service(ServletRequest request,ServletResponse response){
}
![Page 20: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/20.jpg)
22/04/23 20
destroy() method
- is called at servlet unloading
- all cleanup activities can be done here (closing db/socket connections,updating log files)
public void destroy(){
}
![Page 21: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/21.jpg)
22/04/23 21
There are 2 steps in order to build & deploy a servlet-based application
(A) Development Phase : - Write the servlet class with the required application logic- Compile the servlet class
(B) Deployment Phase :- Deploy the servlet in the webserver
![Page 22: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/22.jpg)
22/04/23 22
Redirection• At times outdated/old URLs need to be redirected to new ones
so that the user does not see an error when the URL is accessed
• In such situations,URL redirection option allow us to forward the request to new location
Several situations in which the URL needs to be changed- when the document moves to new URL- when the application is enhanced to include more pages- when the user goes to final order page w/o filling the requisite order details
URL redirection can be achieved by using(A) sendRedirect method of HttpServletResponse interface(B) forward method of RequestDispatcher interface
“redirect” means sending response from servlet to the browser
telling it to go to another URL
![Page 23: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/23.jpg)
22/04/23 23
Conclusion
![Page 24: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/24.jpg)
22/04/23 24
![Page 25: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/25.jpg)
22/04/23 25
Question & Answers
??
![Page 26: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/26.jpg)
22/04/23 26
Java on Server-side • Robust• Scalable• Open• Fast• Portable• Well integrated• Extensible & flexible
![Page 27: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/27.jpg)
22/04/23 27
Advantages over other techniques
• Generally much faster than CGI scripts
• A different process model is used.• Standard API• Supported by many web servers.• All the advantages of the Java--Ease of development--Large API
![Page 28: 21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.](https://reader034.fdocuments.in/reader034/viewer/2022051517/5697bfdb1a28abf838cb0a6c/html5/thumbnails/28.jpg)
22/04/23 28
Session Tracking