How to reference web component init parameters

In Sun AppServer, where are the web component init parameters stored?

ServletContext only contains init parameters for WAR context init parameters, ServletConfig only contains some system parameters. Is there anything I overlooked? I began to suspect that I can not reference those parameters in the code. If that's true, what good is it to set these init parameters?

[382 byte] By [jjj110200a] at [2007-9-23]
# 1
For each Servlet and JSP you can define init-parameters in the web.xml file: http://e-docs.bea.com/wls/docs61/webapp/web_xml.html#1016477
tolmanka at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for the reply. But my question is: after I define the init parameters, how can I reference them in the API? something like ***.getInitParameter(). ServletContext and ServletConfig has this method has none of them have the we component init parameters.
jjj110200a at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

http://www.sap-img.com/java/difference-between-servletcontext-and-servletconfig.htm

For ex: If you want the name of your company or your E-mail address appear in all the pages of your web application then you use ServletContext.

<context-param>

<param-name>Developer</param-name>

<param-value>Crazy@weird.com</param-value>

</context-param>

In the above xml entry you set the value of Context Parameter i.e Developer as Crazy@Weird.com. By making the above entry into your web.xml file you can get the value of the ontext parameter 'Developer' anywhere throughout your web application. You can have any number of such context parameters.

String s =

getServletContext.getInitParameter("Developer");

You can have the above statement in any of your servlets to get the value of the String s as "Crazy@Wierd.com". So you are setting the parameter Developer in the web.xml as a Context paramter (which is available throughout the webapp). You get these Context Paramters using a ServletContext object as shown in the statement above.

Coming to ServletConfig, its a more specific one. The ServletContext is for the whole web-app but the ServletConfig is for one particular Servlet.

When you want paramters which cannot be hardcoded in your servlet you use ServletConfig. I cant think of a good example at the moment. Lets do with a lame one;).Lets consider you need to have a String value which tells you what a particular servlet does. Remember ServletConfig is for a particular servlet and not for the entire Application.

The web.xml file may look like this:

<servlet>

<servlet-name>Select</servlet-name>

<servlet-class>Select</servlet-class>

<init-param>

<param-name>About the Servlet</param-name>

<param-value>This Servlet gives you a list of

colors to select from</param-value>

</init-param>

</servlet>

The above entry into a web.xml file is for a servlet named Select. <Please note that you are writing the entry within a Servlet tag which means that this is for a particular servlet. Unlike for ContextParamter where we did not write under any particular servlet

tag since it was for the whole application.> Within the Servlet tag you set the value for a Servlet paramter called "About the Servlet".

So whenever you do getServletConfig().getInitParamter("About the Servlet") you will get a string "This Servlet gives you a list of colors to select from". You get this value only when you call within the servlet called Select because you have set the paramter only for that particular servlet. Unlike context paramters which you could access anywhere using ServletContext.

To sum it up, every servlet has the same ServletContext but it also has its own ServletConfig.

tolmanka at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
This is handled in the init(ServletConfig config) method of the Servlet class. The ServletConfig object is provided by the ServletContainer and is populated wih the init parameters you have specified.
linxpdaa at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...