Differences between servlet context and servlet config?

Questions by divya_a

Showing Answers 1 - 8 of 8 Answers

santh kumar

  • Feb 5th, 2006
 

     ServletConfig is assosiated with Servlet Where as ServletContext is

    assosiated with Web Application(or context path).

    Come 2 DD(web.xml) perspective,

   The data In <init-param> tag is specific 2 that perticular servlet.u can

  use that for logging purpose.bt the data in <context-param> is specific

 2 web application.i mean all the servlets can share the data present in that

 tag.

   Container creates an object of ServletConfig for each Servlet.it maintains

  an object of ServletContext for each Web Application(or context path).

  Was this answer useful?  Yes

Kaushik

  • Feb 12th, 2006
 

Servlet context describes about webcontainer, Every web-container have only  one Servlet- context.

Servlet- config information about the web-application.

So Every web-application have one Servlet config.

every web-container have one servlet-context

Webcontainer is responsibility to create the objects of Servlet-context.

  Was this answer useful?  Yes

M.Manish

  • Feb 13th, 2006
 

ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized

ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet.

  Was this answer useful?  Yes

Ashish A

  • Feb 23rd, 2006
 

Sorry, But here is a request for all (especially for Kaushik), Please don't post wrong concepts here because lots of people visits this site to get their concepts clear.

Servlet context is not associated with a Web container but with a particualr Web application. when a web Server (or specifically a Web container) deploys a web application, it creates a 'Servlet context' object which is available for all Servlets (and Filters) in that particualr web application. And every web application has it's own Servlet context object.

A Servlet config object is associated with a particualr Servlet. This contain information related to a particualr servlet only.

A Servlet context is typically used for communication and information sharing between different servlets of a particualr web application while a servlet config is used typically to pass some initial parameters to the servlet through web.xml. 

  Was this answer useful?  Yes

Rajkumar

  • Apr 24th, 2006
 

Hi Kaushik,

          Its Raj here, I need to make a small correction in ur Post,

As a ServletConfig is one per Servlet Instance and not for the Web App.

Hope u ill make change in ur view, or else go thro' some investigation n make it clear....

Best Regards Rajkumar

  Was this answer useful?  Yes

suma tv

  • Feb 22nd, 2007
 

java servlets and jsp

  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