aspose file tools*
The moose likes Servlets and the fly likes what is the need of writing <listener-class> in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "what is the need of writing <listener-class> in web.xml" Watch "what is the need of writing <listener-class> in web.xml" New topic
Author

what is the need of writing <listener-class> in web.xml

jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
Hi,

why to write <listener-class> in web.xml ? I see that container would understand that the class is a listner class by seeing that that class has implemented listener interface. Then, if it doesn't make any difference to specify <listener-class> ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

"listener" not "listner". Programming is all about precision and accuracy.

There needs to be some element to declare the class. What's wrong with calling it what it is?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
didn't get you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

  • Watch your spelling.
  • Why not call it listener class? What would you call it?
  • Ankit Garg
    Sheriff

    Joined: Aug 03, 2008
    Posts: 9280
        
      17

    The container doesn't check every class in your application if it is a listener class or not. Only listeners declared in the web.xml are registered for listening to events by the container...


    SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
    Sharad Jadhav
    Greenhorn

    Joined: Feb 10, 2010
    Posts: 18
    jazy smith wrote:Hi,

    why to write <listener-class> in web.xml ? I see that container would understand that the class is a listener class by seeing that that class has implemented listener interface. Then, if it doesn't make any difference to specify <listener-class> ?


    I am also agree with you. But I also don't know.


    Java J2EE Hibernate Spring
    James Tharakan
    Ranch Hand

    Joined: Aug 29, 2008
    Posts: 580

    I think it makes sense in telling the container that these are the listener class because imagine a situation where in a application has hundreds of class and container has to go through each and every class to find out if they are listener implementer or not !!


    SCJP 6
    Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: what is the need of writing <listener-class> in web.xml
     
    Similar Threads
    Free resources when session times out
    404-tried everything
    context variable in action servlet
    Problem JSF as RuntimeException: Cannot find FacesContext
    Spring JSF integration doubt