I mean how to get the params defined in DD by method? like, <servlet> <init-param> <parm-name>id</parm-name> <parm-value>foo</parm-value>
Amanda Fu
Ranch Hand
Joined: Jul 17, 2003
Posts: 31
posted
0
where i am confused is that <context-param> and <init-param>. context.getInitParamter() will retrieve from <context-param> or <init-param>?
Phil Rhodes
Ranch Hand
Joined: Dec 27, 2003
Posts: 65
posted
0
ServletContext.getInitParameter() will get the context-wide init parameter defined by <context-param>, yes. And ServletConfig.getInitParameter() will retrieve the servlet specific init parameter defined by <init-param>.
A+, Network+, SCJP, SCWCD<br />preparing for SCBCD, SCEA, CompTIA I-Net+
Lou Caudell
Ranch Hand
Joined: Oct 06, 2001
Posts: 32
posted
0
What may add additional confusion here is the issue of how would one address a redundantly named parameter. // web.xml <servlet> <servlet-name>servlet1</servlet-name> <servlet-class>com.servlet1</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
How would one address the non-unique <init-param> "debug" with getinitParmeter() and retreive the desired value from the correct <servlet-name>. As you can see each servlet has a debug parameter.
I have accessed an implemented subclass class Servlet1_XML_Param { public static final String DEBUG = "debug"; } and passed the static value.
to obtain the value, but how do you do it by just passing a string?
Chandra Sagi
Ranch Hand
Joined: May 05, 2005
Posts: 162
posted
0
There could be two <init-param>'s with the same name in two different Servlets since they belong only to the ServletConfig of each Servlet and are unique. But the same cannot be true for <context-param> since they are for the whole application.
One Servlet cannot access the <init-param> of other Servlets whereas <context-param> can be accessed by any Servlet and could be changed. We use getServletConfig.getInitParameter("") to retrieve <init-param>'s and getServletContext.getInitParameter("") to retrieve <context-param>'s.
So, there is no Context parameters defined in the web.xml. Therefore when you try to get the Init parameters through ServletContext getInitiParameter method. It always return null.
If you relly want to access the application level paramenter "debug", try the follwing web.xml.
Hope it help you.
Thanks
Salvador Cecilio
Ranch Hand
Joined: Dec 20, 2004
Posts: 41
posted
0
Originally posted by Amanda Fu: where i am confused is that <context-param> and <init-param>.
context.getInitParamter() will retrieve from <context-param> or <init-param>?
I was just looking at this and was confused until I figured it out.
To get the init-param value:
To get the context-param value:
SCJP 1.4 - 93%
SCWCD 1.4 - 89%
IBM FileNet 3.5 - Developer
IBM FileNet 3.5 - Administrator
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: what's the corresponding method for init-param?