Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParameter()

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
what is the difference between ServletConfig.getInitParameter() and ServletContext.getInitParameter() ?
Thank you in advance.
 
Stephen Tallamy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletConfig contains information specific to that servlet. ServletContext contains information about the web application the servlet is a member of.
Generally you use ServletContext to get global set-up parameters such as the webmaster's email addres or a central database. ServletConfig is used more for specific initalisation parameters for the servlet.
Here is an example web application descriptor:

In this example, param1 is available through the ServletContext of both MyServlet and MyOtherServlet. param2 is available through the ServletConfig of MyServlet only. param3 is available through the ServletConfig of MyOtherServlet only.
Hope this helps.
 
Rohit Poddar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) ServletContext is same for all the servlets in that Web application i.e. there is only one ServletContext per Web App. per JVM. And hence ServletContext.getInitParameter() will give same parameter values to each Servlet in thar web app.
ServletConfig is the object passed to Servlet by container to give initialization information (which is different for different Servlets) for that servlet as oppose to Servlet Context (which is one per Web APp per JVM) and hence ServletConfig.getInitParameter() might give different values in each servlet.
2) Servlet COntext init parameters are specified in web.xml using <context-param></context-param> tag whereas Servlet init params are specified by <servlet><init-param></init-param></servlet>
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well explained Rohit....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic