What is the difference between servlet config and servlet
context.

Answers were Sorted based on User's Feedback



What is the difference between servlet config and servlet context...

Answer / mansi

• Signature: public interface ServletConfig
ServletConfig is implemented by the servlet container to
initialize a single servlet using init(). That is, you can
pass initialization parameters to the servlet using the
web.xml deployment descriptor. For understanding, this is
similar to a constructor in a java class.
Example code:
<servlet>
<servlet-name>ServletConfigTest</servlet-name>
<servlet-class>com.javapapers.ServletConfigTest</servlet-class>
<init-param>
<param-name>topic</param-name>
<param-value>Difference between ServletConfig and
ServletContext</param-value>
</init-param>
</servlet>
• Signature: public interface ServletContext
ServletContext is implemented by the servlet container for
all servlet to communicate with its servlet container, for
example, to get the MIME type of a file, to get dispatch
requests, or to write to a log file. That is to get detail
about its execution environment. It is applicable only
within a single Java Virtual Machine. If a web applicationa
is distributed between multiple JVM this will not work. For
understanding, this is like a application global variable
mechanism for a single web application deployed in only one JVM.
The ServletContext object is contained within the
ServletConfig object. That is, the ServletContext can be
accessed using the ServletConfig object within a servlet.
You can specify param-value pairs for ServletContext object
in <context-param> tags in web.xml file.
Example code:
<context-param>
<param-name>globalVariable</param-name>
<param-value>javapapers.com</param-value>
</context-param>

Is This Answer Correct ?    1 Yes 0 No

What is the difference between servlet config and servlet context...

Answer / vkrishna88

ServletConfig:
1)An object of ServletConfig exists one per Servlet...
2)An object of ServletConfig will be created when
init(ServletConfig)method is executed...
3)The data to a servlet which related to ServletConfig
object must be written in <init-param>....</init-param> with
in <servlet>…</servlet> of web.xml....
4)An object of ServletConfig will exists as long as a
specific Servlet is executing.

ServletContext:
1)An object of ServletContext exists one per web application....
2)An object of ServletContext will be created when we deploy
the web application in servlet container or servlet
execution environment......
3)The common data or global data related to ServletContext
must be written under <context-param>…</context-param> with
in <web-app>....</web-app> and outside of
<servlet>...</servlet> of web.xml....
4)An object of ServletContext will exists until the entire
web application completed its execution.....

Is This Answer Correct ?    1 Yes 0 No

What is the difference between servlet config and servlet context...

Answer / suresh g

Question: What is the difference between servlet config and servlet context?

Servlet Context:
Servlet context is communication between server side .Every application has only one servlet context and is accessible to all action resource of that application.

Serclet Config:
Servlet Config is objcet created after a servlet is instantiation and its default constructor is read .It is create to pass initialization information the servlet.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between servlet config and servlet context...

Answer / suresh g

Servlet Context:
Servlet context is communication
between server side .Every application has only one
servlet context and is accessible to all action
resource of that application.

Serclet Config:
Servlet Config is objcet created after
a servlet is instantiation and its default constructor
is read .It is create to pass initialization
information the servlet.

Is This Answer Correct ?    1 Yes 1 No

What is the difference between servlet config and servlet context...

Answer / vijay kaarmani

Both ServletConfig and ServletContext are configuration objects used by servlet container to initialize various init parameters for a web application. However they differ in terms of the scope and availability of init parameters defined by both of them.

Please see http://javashiksha.com/servlet-jsp/difference-between-servlet-config-and-servlet-context.html for more details

Is This Answer Correct ?    0 Yes 0 No

What is the difference between servlet config and servlet context...

Answer / gopinath

Servlet Context is way to create the application object.

Servlet Context is way to create Servlet Parameters

Is This Answer Correct ?    0 Yes 0 No

What is the difference between servlet config and servlet context...

Answer / v.tulasiprasad

servlet config is used to obtain configuration data when it
is loaded in to the application server.
for each servlet servlet config will be indipendent and the
configuration of a servlet is intialized in the servlet
config file.

servlet context is used to obtain the information about the
environment in which it is running.one application have only
one servlet context file.through this servlet context file
we can acces servlets in that application.

Is This Answer Correct ?    10 Yes 14 No

What is the difference between servlet config and servlet context...

Answer / nahim makhani

Servlet context is used for every servlet of package and
servlet config
is used for particular one servlet

Is This Answer Correct ?    5 Yes 12 No

What is the difference between servlet config and servlet context...

Answer / ravikiran.chd

servlet config is used to configure the deploy time
constants per servlet
Servlet context is used to configure the deploy time
constants per web application

Is This Answer Correct ?    5 Yes 14 No

Post New Answer

More Servlets Interview Questions

How do you load an image in a Servlet?

0 Answers  


Can we write a constructor for a Servlet class ? if yes how ? if no why not ?

10 Answers  


How values can be passed from HTML page to servlet?

7 Answers   ABC,


What are the objects involved when a servlet receives a call from client?

0 Answers  


Why should we go for interservlet communication?

2 Answers  






What are the phases of the servlet life cycle?

0 Answers  


What is the need of servlet filters?

0 Answers  


What’s the difference between forward() and sendredirect() methods?

0 Answers  


What are the life-cycle methods for a servlet?

0 Answers  


How two servlets communicate with each other?

2 Answers  


waht is the main diference b/w servelts and JSP ?

8 Answers   CAP, HCL,


What are the types of protocols supported by httpservlet ?

0 Answers  


Categories