wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet Context parameters query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet Context parameters query" Watch "Servlet Context parameters query" New topic
Author

Servlet Context parameters query

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1086
    
    1

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



Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

So it's not allowed :P Only the last one matters in this case.
You should do something like this:



SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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

Joined: Feb 29, 2008
Posts: 1086
    
    1

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
 
 
subject: Servlet Context parameters query