File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Naming of servletContext Initialization parameter

 
riohk kurn
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 569
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()....
 
Hema Menon
Ranch Hand
Posts: 569
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic