File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlet Context and Servlet Config Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Context and Servlet Config" Watch "Servlet Context and Servlet Config" New topic
Author

Servlet Context and Servlet Config

Pandian Raman
Greenhorn

Joined: Jun 21, 2011
Posts: 12
What is the functionality of both Servlet Context and Servlet Config and when both will get initilized and destroyed?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

pandian raman wrote:What is the functionality of both Servlet Context and Servlet Config and when both will get initilized and destroyed?


The same question has been asked about people.

The Servlet Context exists for the life of the webapp. The Servlet Config is the information taken from the web.xml file.


Customer surveys are for companies who didn't pay proper attention to begin with.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

pandian raman wrote:What is the functionality of both Servlet Context and Servlet Config and when both will get initilized and destroyed?

initialization:
ServletContext-after application deployed into server
ServletConfig-after servlet initialized(in init method)
destruction:
ServletContext-after application undeployed
ServletConfig-after servlet unloaded
Pandian Raman
Greenhorn

Joined: Jun 21, 2011
Posts: 12
Thanks Tim.

Thanks Seetharaman.

Seetharaman,

You mean the servlet config will initilized for each and every servlet request.

Regards,
Pandian R
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

pandian raman wrote:
Seetharaman,
You mean the servlet config will initilized for each and every servlet request.

servlet get initialized in init method. and there is only one instance for a servlet regardless request.
container creates thread for every request and runs on a single servlet instance.
So, Only one time servlet config get initialized and it is used to get servlet specific values from web.xml also to get ServletContext object.

Pandian Raman
Greenhorn

Joined: Jun 21, 2011
Posts: 12
Seetharaman,

Cool man, i have absolutely got your point. I am clear now, thanks dude.

Regards,
Pandian R
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Already answered in the ServletsFaq. Please check the FAQ before posting.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Context and Servlet Config