| Author |
Naming of servletContext Initialization parameter
|
riohk kurn
Ranch Hand
Joined: Oct 19, 2002
Posts: 31
|
|
HI, There are two terms: one is coming from the descriptor, and we get it from context.getInitParameter(XXX). The second is from context.getAttribute(XXX). 1)Are they called servlet context initialization parameters and servlet initialization parameters respectively? 2)Do parameter that is set by getAttribute() shared all servlets in web application? 3)parameter that is specified by descriptor is only for the defined servlet?
|
 |
Hema Menon
Ranch Hand
Joined: Oct 29, 2000
Posts: 569
|
|
There are two terms: one is coming from the descriptor, and we get it from context.getInitParameter(XXX). The second is from context.getAttribute(XXX). 1)Are they called servlet context initialization parameters and servlet initialization parameters respectively? Servlet Specifications refers them as initialization parameters[SRV3.3] and Context Attributes[SRV 3.4] 2)Do parameter that is set by getAttribute() shared all servlets in web application? The parameter thas is set by setAttribute() is available to any servlet that is part of the same web application.[SRV3.4] Thanks, Hema
|
 |
yi zhu
Ranch Hand
Joined: Sep 10, 2002
Posts: 41
|
|
2)Do parameter that is set by getAttribute() shared all servlets in web application? Yes. The scope of object stored in ServletContext is Application 3)parameter that is specified by descriptor is only for the defined servlet? Yes
|
 |
yi zhu
Ranch Hand
Joined: Sep 10, 2002
Posts: 41
|
|
There are actually 2 types of init parameter for a servlet. one is from ServletConfig, which is available only to this servlet. The other is from ServletContext, which is available for all servlets.
|
 |
Rama Raghavan
Ranch Hand
Joined: Aug 22, 2001
Posts: 116
|
|
There are actually 2 types of init parameter for a servlet
This statement may be incorrect or not accurately phrased. ServletConfig and ServletContext are 2 different objects. Just that context initialization parameters are available any servlet in that web application.
The parameter thas is set by setAttribute() is available to any servlet that is part of the same web application.[SRV3.4] Thanks, Hema
Agreed that objects bound to ServletContext via setAttribute() is available to any servlet. But, in a distributed environment, where the same application is deployed on multiple servers, there will be one context object per JVM. Parameters bound to context on one JVM will not be available to servlets of the same application running on a second JVM. So - ServletContext may not always be the right place to store global information for use by getAttribute()....
|
Rama Raghavan<br />SCJP2<br />SCWCD
|
 |
Hema Menon
Ranch Hand
Joined: Oct 29, 2000
Posts: 569
|
|
Originally posted by Rama Raghavan: But, in a distributed environment, where the same application is deployed on multiple servers, there will be one context object per JVM. Parameters bound to context on one JVM will not be available to servlets of the same application running on a second JVM. So - ServletContext may not always be the right place to store global information for use by getAttribute()....
True. The context attributes are local only to the VM where it gets created. In distributed environment, alternate ways need like adding attributes to a session or so should be used. Thanks, Hema
|
 |
 |
|
|
subject: Naming of servletContext Initialization parameter
|
|
|