• Post Reply Bookmark Topic Watch Topic
  • New Topic

THREE (3) flavors of getInitParameter

 
John Strong
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?
 
Bryan Basham
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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!