j2ee web fundamentals lesson 4 request and response
DESCRIPTION
J2EE Web Fundamentals Lesson 4 Request and Response. Instructor: Dr. Segun Adekile. Outline. Objectives Course Text Book Basham, Bryan; Sierra, Kathy; Bates, Bert (2012-10-30). Head First Servlets and JSP (Kindle Location 1349). O'Reilly Media. Kindle Edition. Request and Response - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/1.jpg)
J2EE Web FundamentalsLesson 4
Request and Response
Instructor: Dr. Segun Adekile
![Page 2: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/2.jpg)
Outline
• Objectives• Course Text Book– Basham, Bryan; Sierra, Kathy; Bates, Bert (2012-
10-30). Head First Servlets and JSP (Kindle Location 1349). O'Reilly Media. Kindle Edition.
• Request and Response– Being a Servlet
![Page 3: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/3.jpg)
Objectives
![Page 4: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/4.jpg)
Agenda
• How the Container Handles a Request• Servlet Lifecycle– Loading– Initialization– Service• HTTP Methods• Request Object• Response Object
• Response Redirect• Request Dispatch
![Page 5: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/5.jpg)
How the Container Handles a Request
![Page 6: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/6.jpg)
How the Container Handles a Request
![Page 7: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/7.jpg)
How the Container Handles a Request
![Page 8: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/8.jpg)
Servlet Lifecycle• The servlet lifecycle is simple
• There is only one main state – initialized
• If the servlet isn’t initialized, then it’s either being initialized (running its constructor or init() method), being destroyed (running its destroy() method), or it simply does not exist
![Page 9: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/9.jpg)
Servlet Lifecycle
![Page 10: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/10.jpg)
Servlet Lifecycle
![Page 11: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/11.jpg)
Servlet Lifecycle
![Page 12: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/12.jpg)
Servlet Loading• When the Container starts, it looks for deployed web apps
and then starts searching for servlet class files– Finding the class is the first step– Loading the class is the second step, and it happens either on Container
startup or first client use. Your Container might give you a choice about class loading, or it might load the class whenever it wants.
![Page 13: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/13.jpg)
Servlet Initialization• The constructor makes only an object• To be a servlet, the object needs to be granted servletness, getting all the unique privileges that come with being a servlet e.g. its ServletContext reference.
• You can override the init() method to add operations such as getting a db connection or registering yourself with other objects.
![Page 14: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/14.jpg)
Servlet Initialization
![Page 15: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/15.jpg)
Servlet Service: Request and Response
![Page 16: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/16.jpg)
Servlet Service - HTTP Methods
![Page 17: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/17.jpg)
Servlet Service - HTTP MethodsIntended use:
• for getting things
• Idempotent
Intended use:
• for sending data to be processed
• Non-idempotent
![Page 18: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/18.jpg)
Servlet Service - HTTP Methods
![Page 19: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/19.jpg)
Sending and using a single parameter
getParameterValues – for multiple values
![Page 20: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/20.jpg)
Servlet Service – Request Object
![Page 21: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/21.jpg)
Lifecycle key points
![Page 22: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/22.jpg)
HTTPServletRequest key points
![Page 23: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/23.jpg)
Servlet Service – Response Object• The response is what goes back to the client.• It is parsed and rendered by the browser.• Typically the response object is used to get an • output stream which is used to write the HTML, which goes back to the client.
![Page 24: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/24.jpg)
Response Redirect
![Page 25: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/25.jpg)
Response Redirect
![Page 26: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/26.jpg)
Request Dispatch
![Page 27: J2EE Web Fundamentals Lesson 4 Request and Response](https://reader036.vdocument.in/reader036/viewer/2022062411/56816935550346895de08ebc/html5/thumbnails/27.jpg)
HTTPServletResponse key points