• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParameter() method

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • 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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • 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 ]
     
    Varsha Garud
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Frank it was very helpfull to me..
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic