• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Marty, what's the place of new listeners in life cycle?

 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marty,
I'm relatively new to the Java web technologies. These days, Sun's bringing up the new specs for Servlets and JSP. Could you provide a couple of descriptive examples for the newly defined listeners (what events they are capable of handling and the objects generating these events).
Thanks.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the image below might introduce you to the newly-defined ServletRequestListener... U may find more info in Chapter-SRV10 of the Servlet 2.4 Spec... Here is some explanation on it

Servlet Request Events
*Lifecycle-A servlet request has started being processed by Web components.
javax.servlet.ServletRequestListener
*Changes to attributes-Attributes have been added, removed, or replaced on a
ServletRequest.
javax.servlet.ServletRequestAttributeListener


 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

These days, Sun's bringing up the new specs for Servlets and JSP. Could you provide a couple of descriptive examples for the newly defined listeners (what events they are capable of handling and the objects generating these events).


Well, there are only two new Web application lifecycle event listeners in the new servlet 2.4 spec: ServletRequestListener and ServletRequestAttributeListener. These are slightly useful, perhaps, but hardly critical. So, if you are new to servlet and JSP programming, I definitely wouldn't start here. I wouldn't even start with listeners in general, even though the listeners that were introduced in the servlet 2.3 spec are a bit more generally useful (for details on their use, see Chapter 10 of http://www.moreservlets.com/).
That being said, here is what they do:
  • ServletRequestListener: triggered when the the first servlet, JSP page, or filter in the chain starts processing the request. You might use this to introduce certain servlet request attributes for ALL requests (perhaps for testing and debugging how they handle certain situations) or for logging (eg to trace all requests that have a certain cookie).
  • ServletRequestAttributeListener: triggered when someone adds, removes, or replaces attributes (not parameters!) in the ServletRequest. You usually use these attributes in the MVC architecture, so this listener might let you keep track of this, or automatically make side effects when certain attributes are added.


  • Again, I do not think that these two new listeners are very important, so don't focus on them if you are new to this technology.
    Cheers-
    - Marty
     
    Ranch Hand
    Posts: 8953
    Firefox Browser Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In my opinion I dont see any use of having listeners for HttpServletRequest.
    Any other opinions?
     
    Vad Fogel
    Ranch Hand
    Posts: 504
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you very much for this informative response, Marty!
     
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    I found (IMHO) very difficult to figure it out some good practical examples for ServletRequestAttributeListener and ServletRequestListener. I read the explanations of Marty, but even so, and besides debugging purposes, I cannot see real practical use of those listeners.
    What do the people that vote for the introduction of those listeners say about that? What does the expert group say about that? I mean, what are the real needs for the introduction of those listeners in servlet 2.4?
    Marty, do you have some other real good practical examples to clarify us?
    Dani Mazzuca
     
    Marty Hall
    Author
    Posts: 111
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I found (IMHO) very difficult to figure it out some good practical examples for ServletRequestAttributeListener and ServletRequestListener. I read the explanations of Marty, but even so, and besides debugging purposes, I cannot see real practical use of those listeners.
    What do the people that vote for the introduction of those listeners say about that? What does the expert group say about that? I mean, what are the real needs for the introduction of those listeners in servlet 2.4?
    Marty, do you have some other real good practical examples to clarify us?


    My guess is that they just wanted to be consistent in the kind of listeners they provide. These new ones for the request parallel the existing ones for the session.
    No, I don't see a lot of use for them either beyond the simple debugging examples I cited.
    Cheers-
    - Marty
     
    If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
    Clean our rivers and oceans from home
    https://www.kickstarter.com/projects/paulwheaton/willow-feeders
    reply
      Bookmark Topic Watch Topic
    • New Topic