• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference betwees ServletContext and ServletConfig ?

 
samakee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
Could you please tell me what the difference between ServletContext and ServletConfig. Why they both have same methods
- getInitParameter()
- getInitParameterNames()

When to use which one and How?

Thanks,
Samakee
 
Raj Paul
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletConfig initialization parameters are for specific servlet but ServletContext initialization parameters are for all the servlets present in one application.
For ServletConfig the init paramters through
<init-param></init-param> tag
and for ServletContext the init parameters through
<context-param></context-param>

Thanks & Regards,
Mike
 
Mehul Jasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Mike.
ServletContext init params are used for web application, while servletconfig init params are used for a specific servlet.
Scope of ServletContext is on entire web application, while scope of ServletConfig is limited to a specific servlet.
 
samakee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.. Samakee.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samakee,
JavaRanch has a Naming Policy Compliance with the policy is required to be entered in the drawing for a giveaway. Please reregister with a proper name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic