SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a Servlet Event framework

Reviving the HTTP Service - Felix Meschberger
Reviving the HTTP Service - Felix MeschbergerReviving the HTTP Service - Felix Meschberger
Reviving the HTTP Service - Felix Meschbergermfrancis
 
Whats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix MeschbergerWhats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix Meschbergermfrancis
 
Restful web services_tutorial
Restful web services_tutorialRestful web services_tutorial
Restful web services_tutorialphilip75020
 
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017VMware Tanzu
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartSPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartJenkins NS
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Augemfrancis
 
Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
Reactive OSGi meets Reactive Java - Don’t cross the streams - T WardReactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
Reactive OSGi meets Reactive Java - Don’t cross the streams - T Wardmfrancis
 
SCULPT! YOUR! TESTS!
SCULPT! YOUR! TESTS!SCULPT! YOUR! TESTS!
SCULPT! YOUR! TESTS!Taras Oleksyn
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APISalesforce Developers
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Jens Ravens
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroMohammad Tayseer
 
Moving full trust code to the cloud using repeatable patterns and best practices
Moving full trust code to the cloud using repeatable patterns and best practicesMoving full trust code to the cloud using repeatable patterns and best practices
Moving full trust code to the cloud using repeatable patterns and best practicesLuis Valencia
 
ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008Caleb Jenkins
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Developmentjoelabrahamsson
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...Edureka!
 

Semelhante a Servlet Event framework (20)

Reviving the HTTP Service - Felix Meschberger
Reviving the HTTP Service - Felix MeschbergerReviving the HTTP Service - Felix Meschberger
Reviving the HTTP Service - Felix Meschberger
 
Servlets
ServletsServlets
Servlets
 
java
java java
java
 
Whats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix MeschbergerWhats New in the Http Service Specification - Felix Meschberger
Whats New in the Http Service Specification - Felix Meschberger
 
Restful web services_tutorial
Restful web services_tutorialRestful web services_tutorial
Restful web services_tutorial
 
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartSPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx Webpart
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
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
Reactive OSGi meets Reactive Java - Don’t cross the streams - T WardReactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward
 
SCULPT! YOUR! TESTS!
SCULPT! YOUR! TESTS!SCULPT! YOUR! TESTS!
SCULPT! YOUR! TESTS!
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. Castro
 
Mashups
MashupsMashups
Mashups
 
Servlet Filter
Servlet FilterServlet Filter
Servlet Filter
 
Moving full trust code to the cloud using repeatable patterns and best practices
Moving full trust code to the cloud using repeatable patterns and best practicesMoving full trust code to the cloud using repeatable patterns and best practices
Moving full trust code to the cloud using repeatable patterns and best practices
 
ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008ASP.NET AJAX with Visual Studio 2008
ASP.NET AJAX with Visual Studio 2008
 
Python reliable delivery
Python reliable deliveryPython reliable delivery
Python reliable delivery
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
 

Mais de AshishSingh Bhatia

Mais de AshishSingh Bhatia (6)

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

Último

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Último (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 

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