This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes getInitParameter() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getInitParameter() method" Watch "getInitParameter() method" New topic
Author

getInitParameter() method

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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 ]

    Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
    Varsha Garud
    Greenhorn

    Joined: Jan 18, 2013
    Posts: 2
    Thank you Frank it was very helpfull to me..
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: getInitParameter() method