1 / 35

J2EE Web Fundamentals Lesson 5 Attributes and Listeners

J2EE Web Fundamentals Lesson 5 Attributes and Listeners. 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. Attributes and Listeners

gitel
Download Presentation

J2EE Web Fundamentals Lesson 5 Attributes and Listeners

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. J2EE Web FundamentalsLesson 5Attributes and Listeners Instructor: Dr. Segun Adekile

  2. 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. • Attributes and Listeners • Being a Web App

  3. Objectives

  4. Agenda • Init Parameters • Context Init Parameters • ServletConfig VS. ServletContext • ServletContextListener • The Eight Listeners • Attributes • Request Dispatching

  5. Init Parameters - scenario

  6. Init Parameters - solution

  7. Init Parameters - process

  8. Context Init Parameter - scenario

  9. Context Init Parameter - scenario

  10. Context Init Parameter - solution

  11. ServletConfig VS ServletContext

  12. ServletContext: API

  13. ServletContextListener: process

  14. ServletContextListener: example

  15. ServletContextListener

  16. ServletContextListener

  17. ServletContextListener

  18. ServletContextListener

  19. The Eight Listeners

  20. The Eight Listeners (continued…)

  21. Attributes

  22. Attributes

  23. Attribute API

  24. Attributes

  25. Attribute and Thread Safety • Everyone in the app has access to context attributes, and that means multiple servlets. And multiple servlets means you might have multiple threads, since requests are concurrently handled, each in a separate thread. This happens regardless of whether the requests are coming in for the same or different servlets. • Basham, Bryan; Sierra, Kathy; Bates, Bert (2012-10-30). Head First Servlets and JSP (Kindle Locations 4120-4122). O'Reilly Media. Kindle Edition.

  26. Attribute and Thread Safety

  27. Attribute and Thread Safety

  28. Attribute and Thread Safety • Synchronizing the service method is a spectacularly BAD idea

  29. Attribute and Thread Safety • Are Session attributes thread-safe?

  30. Attributes - Summary

  31. Request Attributes and Request Dispatching • Request attributes make sense when you want some other component of the app to take over all or part of the request. • Our typical, simple example is an MVC app that starts with a servlet controller, but ends with a JSP view. The controller communicates with the model, and gets back data that the view needs in order to build the response. • There’s no reason to put the data in a context or session attribute, since it applies only to this request, so we put it in the request scope.

  32. Request Dispatching • RequestDispatchers have only two methods • forward() and include(). • You can get a RequestDispatcher in two ways: • from the request or from the context. • Regardless of where you get it, you have to tell it the web component to which you’re forwarding the request. In other words, the servlet or JSP that’ll take over.

  33. Request Dispatching

  34. Recap

More Related