• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • 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.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • 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

 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • 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
     
    Pradeep bhatt
    Ranch Hand
    Posts: 8933
    Firefox Browser Java Spring
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Thank you very much for this informative response, Marty!
     
    Dani Mazzuca
    Ranch Hand
    Posts: 70
    • Mark post as helpful
    • send pies
    • 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
    Ranch Hand
    Posts: 111
    • Mark post as helpful
    • send pies
    • 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
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!