• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Context parameters query

 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic