• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Naming of servletContext Initialization parameter

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic