• 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

getInitParameter() method

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this method directly in order to get parameter values by name from a a web.xml for a servlet. Why is it that I see in some examples where people get the ServletContext then make a call to getInitParameter().
Also what is the difference between:
ServletContext ctx = getServletConfig().getServletContext();
ServletContext context = getServletContext();
I know that the second one uses GenericServlet.gstServletContext, but I still do not know what the difference is.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used this method directly in order to get parameter values by name from a a web.xml for a servlet. Why is it that I see in some examples where people get the ServletContext then make a call to getInitParameter().
They get two different sorts of parameter.
The servlet getInitParameter method gets parameters for that specific servlet. The context getInitParameter() gets "context" parameters for the whole context.
Consider the following web.xml fragment from one of my projects:

  • From any servlet, getServletContext().getInitParameter("application.dir") will get "/tmp/barrel"
  • From SetupServlet getInitParameter("default.template") will get "admin"
  • From AdminServlet getInitParameter("script.publish") will get "group all all.html"
  • PageViewServlet has no parameters of its own


  • Has that helped?
    [ January 05, 2004: Message edited by: Frank Carver ]
     
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you Frank it was very helpfull to me..
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic