SlideShare a Scribd company logo
APPLICATION EVENT FRAMEWORK
Prof. AshishSingh Bhatia
1Prof. AshishSingh Bhatia
What and Why ?
 Life cycle methods
 How to respond to major events in the life cycle of the web application
?
 Who will do what ?
 Eight kind of listeners that respond to web life cycle events.
Prof. AshishSingh Bhatia 2
Listeners Interface
 ServletContextListener
 ServletContext AttributeListener
 HttpSessionListener
 HttpSessionAttributeListener
 HttpSessionActivationListener
 HttpSessionBindingListener
 ServletRequest Listener [ 2.4 ]
 ServletRequestAttributeListener [ 2.4 ]
Prof. AshishSingh Bhatia 3
How ?
 Implement the appropriate interface.
 Implement the methods needed to respond to the events of interest.
 Obtain access to the important Web application objects.
 Use these objects.
 Declare the listener.
 Provide any needed initialization parameters.
Prof. AshishSingh Bhatia 4
Take a Case Study and Think out of Box
 We are enterprise level [ Huge Company with lot many pages of web
application ]
 Where company whose name changes frequently
 We need to display company name in all pages [ Servlet / JSP ]
 How we can do that ?
Prof. AshishSingh Bhatia 5
Take a Case Study and Think out of Box
 As it is needed in application wide we will put it in web.xml as context-param
<context-param>
<param-name>companyName</param-name>
<param-value>test.com</param-value>
</context-param>
 In Servlet we will read it using
String name = getServletContext().getInitParameter(“companyName”);
Prof. AshishSingh Bhatia 6
Guess we have 100 [ Servlet / JSP ]
If we forgot to add entry in web.xml ?
Every Servlet / Page will display null
!!!!
Monitoring creation and destruction of Servlet Context
Prof. AshishSingh Bhatia 7
web.xml
Prof. AshishSingh Bhatia 8
JSP File
Prof. AshishSingh Bhatia 9
Take a new case
Prof. AshishSingh Bhatia 10
What if servlet change
the companyName of
context-param ?
Example : asbspace.in
Take a new case
Prof. AshishSingh Bhatia 11
We should ensure that when company
name is changed
formerCompanyName should also be
changed
companyName = asbspace.in
formerCompanyName=test.com
ServletContextAttributeListener
HTML Form
Prof. AshishSingh Bhatia 12
Servlet Changing Name
Prof. AshishSingh Bhatia 13
ServletContextAttributeListener
Prof. AshishSingh Bhatia 14
JSP displaying new and old name of the company
Prof. AshishSingh Bhatia 15
Session Related Listener
 For all Sessions
 ServletContextListener
 ServletContextAttributeListener
 For Specific Sessions
 HttpSessionListener
 HttpSessionAttributeListener
 Counting number of sessions
 HttpSessionListener Interface : sessionCreated and sessionDestroyed
Prof. AshishSingh Bhatia 16
Prof. AshishSingh Bhatia 17
Prof. AshishSingh Bhatia 18
test.jsp
makesession.html
sessioncount.jsp
Prof. AshishSingh Bhatia 19
Prof. AshishSingh Bhatia 20
Cookies must be disabled. So each
jsp load will act as a request and
create a new session
sessioncount.jsp output
Prof. AshishSingh Bhatia 21
Watching for changes in Session Attribute
 HttpSessionAttributeListener interface. Implement attributeAdded,
attributeReplaced, and attributeRemoved
 It gets notified when an object is placed into the session scope for the
first time, replaced by another object, or removed from the session
scope altogether.
Prof. AshishSingh Bhatia 22
Task – Self Study
 Suppose you want to track buying patterns for a specific item (a yacht, in
this case). Of course, you could try to find all servlets and JSP pages that
process orders and change each one to record yacht purchases. That’s an
awful lot of work for what sounds like a simple request, though, and pretty
hard to maintain, anyhow. A much better option is to create a session
attribute listener that monitors the attributes corresponding to order
reservations or purchases and that records the information in the log file for
later perusal by the sales manager.
Prof. AshishSingh Bhatia 23
Calculating Server Request Load
Prof. AshishSingh Bhatia 24
END OF SESSION
25Prof. AshishSingh Bhatia

More Related Content

PDF
Java script
PPT
Software Engineering
PPTX
Clean Code
PPT
TDD, BDD, RSpec
PDF
Vincent's Event Management Framework (Public)
PDF
How to build an event-driven, polyglot serverless microservices framework on ...
PDF
Event Driven-Architecture from a Scalability perspective
Java script
Software Engineering
Clean Code
TDD, BDD, RSpec
Vincent's Event Management Framework (Public)
How to build an event-driven, polyglot serverless microservices framework on ...
Event Driven-Architecture from a Scalability perspective

Similar to Servlet Event framework (20)

PDF
Reviving the HTTP Service - Felix Meschberger
PDF
Servlets
PPTX
PDF
Whats New in the Http Service Specification - Felix Meschberger
PDF
Restful web services_tutorial
PPTX
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
PPTX
SPFx Webinar Loading SharePoint data in a SPFx Webpart
PPTX
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
PDF
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
PDF
Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
PPTX
SCULPT! YOUR! TESTS!
PDF
Leveraging JavaScript Promises and the Bulk API
PDF
Server Side Swift - AppBuilders 2017
PPTX
Understanding ASP.NET Under The Cover - Miguel A. Castro
PPT
Mashups
PDF
Servlet Filter
PPTX
Moving full trust code to the cloud using repeatable patterns and best practices
PPT
ASP.NET AJAX with Visual Studio 2008
PPTX
Python reliable delivery
PDF
Progressive EPiServer Development
Reviving the HTTP Service - Felix Meschberger
Servlets
Whats New in the Http Service Specification - Felix Meschberger
Restful web services_tutorial
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
SPFx Webinar Loading SharePoint data in a SPFx Webpart
Mastering-ASPNET-Web-API-and-RESTful-Patterns.pptx
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
SCULPT! YOUR! TESTS!
Leveraging JavaScript Promises and the Bulk API
Server Side Swift - AppBuilders 2017
Understanding ASP.NET Under The Cover - Miguel A. Castro
Mashups
Servlet Filter
Moving full trust code to the cloud using repeatable patterns and best practices
ASP.NET AJAX with Visual Studio 2008
Python reliable delivery
Progressive EPiServer Development
Ad

More from AshishSingh Bhatia (6)

PDF
JSP : Creating Custom Tag
PDF
Dom Basics
PDF
Java I/O Part 2
PDF
Java I/O Part 1
PDF
Nested and Enum Type in Java
PDF
Http and Servlet basics
JSP : Creating Custom Tag
Dom Basics
Java I/O Part 2
Java I/O Part 1
Nested and Enum Type in Java
Http and Servlet basics
Ad

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Classroom Observation Tools for Teachers
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
GDM (1) (1).pptx small presentation for students
Renaissance Architecture: A Journey from Faith to Humanism
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
VCE English Exam - Section C Student Revision Booklet
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.

Servlet Event framework

  • 1. APPLICATION EVENT FRAMEWORK Prof. AshishSingh Bhatia 1Prof. AshishSingh Bhatia
  • 2. What and Why ?  Life cycle methods  How to respond to major events in the life cycle of the web application ?  Who will do what ?  Eight kind of listeners that respond to web life cycle events. Prof. AshishSingh Bhatia 2
  • 3. Listeners Interface  ServletContextListener  ServletContext AttributeListener  HttpSessionListener  HttpSessionAttributeListener  HttpSessionActivationListener  HttpSessionBindingListener  ServletRequest Listener [ 2.4 ]  ServletRequestAttributeListener [ 2.4 ] Prof. AshishSingh Bhatia 3
  • 4. How ?  Implement the appropriate interface.  Implement the methods needed to respond to the events of interest.  Obtain access to the important Web application objects.  Use these objects.  Declare the listener.  Provide any needed initialization parameters. Prof. AshishSingh Bhatia 4
  • 5. Take a Case Study and Think out of Box  We are enterprise level [ Huge Company with lot many pages of web application ]  Where company whose name changes frequently  We need to display company name in all pages [ Servlet / JSP ]  How we can do that ? Prof. AshishSingh Bhatia 5
  • 6. Take a Case Study and Think out of Box  As it is needed in application wide we will put it in web.xml as context-param <context-param> <param-name>companyName</param-name> <param-value>test.com</param-value> </context-param>  In Servlet we will read it using String name = getServletContext().getInitParameter(“companyName”); Prof. AshishSingh Bhatia 6 Guess we have 100 [ Servlet / JSP ] If we forgot to add entry in web.xml ? Every Servlet / Page will display null !!!!
  • 7. Monitoring creation and destruction of Servlet Context Prof. AshishSingh Bhatia 7
  • 10. Take a new case Prof. AshishSingh Bhatia 10 What if servlet change the companyName of context-param ? Example : asbspace.in
  • 11. Take a new case Prof. AshishSingh Bhatia 11 We should ensure that when company name is changed formerCompanyName should also be changed companyName = asbspace.in formerCompanyName=test.com ServletContextAttributeListener
  • 13. Servlet Changing Name Prof. AshishSingh Bhatia 13
  • 15. JSP displaying new and old name of the company Prof. AshishSingh Bhatia 15
  • 16. Session Related Listener  For all Sessions  ServletContextListener  ServletContextAttributeListener  For Specific Sessions  HttpSessionListener  HttpSessionAttributeListener  Counting number of sessions  HttpSessionListener Interface : sessionCreated and sessionDestroyed Prof. AshishSingh Bhatia 16
  • 18. Prof. AshishSingh Bhatia 18 test.jsp makesession.html
  • 20. Prof. AshishSingh Bhatia 20 Cookies must be disabled. So each jsp load will act as a request and create a new session
  • 22. Watching for changes in Session Attribute  HttpSessionAttributeListener interface. Implement attributeAdded, attributeReplaced, and attributeRemoved  It gets notified when an object is placed into the session scope for the first time, replaced by another object, or removed from the session scope altogether. Prof. AshishSingh Bhatia 22
  • 23. Task – Self Study  Suppose you want to track buying patterns for a specific item (a yacht, in this case). Of course, you could try to find all servlets and JSP pages that process orders and change each one to record yacht purchases. That’s an awful lot of work for what sounds like a simple request, though, and pretty hard to maintain, anyhow. A much better option is to create a session attribute listener that monitors the attributes corresponding to order reservations or purchases and that records the information in the log file for later perusal by the sales manager. Prof. AshishSingh Bhatia 23
  • 24. Calculating Server Request Load Prof. AshishSingh Bhatia 24
  • 25. END OF SESSION 25Prof. AshishSingh Bhatia