Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Context parameters query

 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Have question

Why multiple <param-name /> <param-value /> are allowed within a <context-param> tag?
foeg -


Also noticed that ContextParam1 is overrided by ContextParam2 means in servlets
getServletContext().getInitParameter("ContextParam2") returns "ContextValue2"
and
getServletContext().getInitParameter("ContextParam1") returns null.

I am not able to understand its behaviour.
Please explain


 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's not allowed :P Only the last one matters in this case.
You should do something like this:

 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Abhay.

I tested with <init-param> tag and I got the same output as incase of using <context-param>

In servlet specification 2.4, SRV.13.4 Deployment Diagram says <param-name> and <param-value> is mandatory elements. They showed this by using 'servlet' element(see it is 10th element). I guess the same applies for <context-param> also. They don't showed the number of occurances. I don't know, why 'Tomcat' implemented in this way. If we want multiple param's, generally we use like what 'Lucas' said above.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i understand we should have seperate context param tag for each init param name/value pair.
I was playing around with web.xml and tried placing two name/value param within a single context-param and to my surprise Tomcat did not gave any deployment error/runtime error. Only thing is that param got overrided.

I want to know does this behaviour (overriding on param name/value pair) is dependent on Vendor implementation of J2EE Servlet Specs.
So, is it possible that if i try to run same code on some different Web container (for eg Sun server /BEA Weblogic/IBM Websphere) i might get different result
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic