• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Order of listerner in web.xml

 
Sanjeev BhimaRao
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it necessary that the <listener> element in the DD needs to appear before any of the <servlet> elements for the container to properly instantiate the listener classes first? I read this is a question but HFSJ does not mention anything like this.

Please let me know.
Regards
Sanjeev
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No
 
Sanjeev BhimaRao
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sreeraj.

Even the Javaranch mock has a similar question and it says that the listener needs to be above the servlet element.

Have you tried this out ?

Regards
Sanjeev
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elements in the DD can appear in any arbitrary order

Can you post the original question itself?
 
Sanjeev BhimaRao
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I got the issue. This is the original question

<web-app>
<servlet>
.....
</servlet>
<listener>
<listener-class>com.javaranch.LogListener</listener-class>
</listener>
</web-app>

The above entry in the Deployment Descriptor(DD) will result in which of the following?

1. Create a listener as defined by the com.javaranch.LogListener class.
2. Provide a Log Servlet for the entire application.
3. The webapp will not be loaded due to a parse exception of the DD.
4. Log all session information as they occur.

I had marked "1" as the answer, assuming "servlet-mapping" would be there. That's the reason I went wrong. The result is "3".
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ordering of DD elements are not necessary in latest version i.e. 2.4
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic