This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

THREE (3) flavors of getInitParameter  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As HFSJ points out (p.158) you get different results from the following two invocations:

getServletContext().getInitParameter("foo") (returns context init params),
getServletConfig().getInitParameters("foo") (returns servlet init params).

But there's a third option. Just write:

getInitParameters("foo") (uses method inherited directly from GenericServlet)

QUESTION: If I use the third optioin (i.e. the getInitParameters inherited directly from GenericServlet) does it return context params or servlet params?

Thanks,
- John Strong (pluviosilla@gmail.com)
 
John Strong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I can answer my own question (duh).

getInitParameters(), inherited from Generic servlet, is the same as
getServletConfig().getInitParameters().

In other words, they both return init parameters within the scope of the servlet, i.e. stuff defined in the DD between tags like this:

<init-param> ... </init-param>

getServletContext().getInitParameters() returns parameters within the scope of the entire app, i.e. stuff defined in the DD between tags like this:

<context-param> ... </context-param>

Correct?
 
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, John, you are correct. Good sluething in the code.
-Bryan
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!