This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 15960
    
  19

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: 60800
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
wood burning stoves
 
subject: Servlet Context and Servlet Config
 
Similar Threads
ServletConfig and ServletContext
Unable to get init parameters in servlet
init parameter.
Servlets
Servlet context and config