This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!