• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParamter(String)

 
andy armstrong
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?
 
Mark Howard
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.
 
Fisher Daniel
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic