What is the difference between ServletContext and ServletConfig?

Both are interfaces. The servlet engine implements the ServletConfig interface in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface to the servlet's init() method.The ServletContext interface provides information to servlets regarding the environment in which they are running. It also provides standard way for servlets to write events to a log file.

Showing Answers 1 - 4 of 4 Answers

p_kandukuri

  • Sep 12th, 2005
 

Every web application has one and only one ServletContext and is accessible to all active resource of that application.
Every Servlet have its ServletConfig.

  Was this answer useful?  Yes

Servlet Config
1, Servlet config are one per servlet,
2, It's inside the servlet, it wont accessible to outside the servlet.
ex:
<servlet>
<init-param>
<param-name>
<param-value>
</init-param>
</servlet>

Servlet Context
1, Servlet context are one per web application
2, It can be accessible to all other web application,
Ex, when you want to redirect your page in to JSP it can be possible here.
ex:
<webapp>
<context-param>
<param-name>
<param-value>
</context-param>
</webapp>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions