• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

getInitParamter(String)

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Used in Servlet Config and ServletContext
What is the differences and when should you use which function from which class?
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy
getInitParameter() in ServletConfig and ServletContext both pertain to initialisation parameters defined in the web.xml deployment descriptor. However, the ServletConfig version is used to retrieve the initialisation parameters of a specific servlet in the web application, and the ServletContext version is to retrieve initialisation parameters that pertain to the entire web application as a whole (eg. database connection stuff).
Mark.
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We usually use getServletConfig().getInitParameter() when we want to get value from web.xml :

<web-app>
.....
<servlet>
....
<init-param>
<param-name>Param1</param-name>
<param-value>ValueOfParam1</param-value>
</init-param>
</servlet>
....
</web-app>
And We usually use getServletContext{).getInitParameter() when we want to get value from web.xml :
<web-app>
.....
<context-param>
<param-name>Param1</param-name>
<param-value>ValueOfParam1</param-value>
</context-param>
Correct me if i am wrong...
daniel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!