This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParameter

 
dh chau
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between ServletConfig().getInitParameter() and ServletContext().getInitParameter()?
I don't know when to use ServletContext().getInitParameter(). From API of Sun, this fn returns a String containing the value of the named context-wide initialization parameter. What is the meaning context-wide initialization parameter?
Many thanks!!
 
boyet silverio
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dh chau,
the getInitParameter of servletConfig is used to get the parameter values that were defined in the <init-param> tag of the <servlet> in web.xml e.g.

This params are available only inside the <servlet-class> specified i.e. com.DailyOvertimeServlet.
So inside this servlet, you can retrieve this initialization parameters using
...
String yourName = getServletConfig().getInitParameter("yourName");
...
For the getInitParameter of servletContext, it it used to get the parameter values that were defined in the
<context-param> tag under <web-app> in web.xml

This context parameters are available to all servlets in your web-app i.e. context wide.
Thus, in ANY servlet in your web app, you can retrieve the context parameters using
...
String companyName = getServletContext().getInitParameter("companyName");
...
But don't just take my word on this, write some code, run, and see it happen.
 
Hema Menon
Ranch Hand
Posts: 569
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Related/Similar discussion here.
Hema
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic