Thursday 6 August 2015

What is the main difference between servlet context and servlet config?

ServletConfig

1.ServletConfig available in javax.servlet.*; package
2.ServletConfig object is one per servlet class
3.destroyed once the servlet execution is completed.
4.We should give request explicitly, in order to create ServletConfig object for the first time
5.Object of ServletConfig will be created during initialization process of the servlet
6.This Config object is public to a particular servlet only

ServletContext

1.ServletContext available in javax.servlet.*; package
2.ServletContext object is global to entire web application
3.Object of ServletContext will be created at the time of web application deployment
4.Scope: As long as web application is executing, ServletContext object will be available, and 5.it will be destroyed once the application is removed from the server.
6.ServletContext object will be available even before giving the first request