aspose file tools*
The moose likes Servlets and the fly likes Servlet Config and Servlet Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Config and Servlet Context" Watch "Servlet Config and Servlet Context" New topic
Author

Servlet Config and Servlet Context

Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
Hi all,

What is the use of servlet config and servlet context.
can any one help me.

thanks in advance
Abhay
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

you should have searched before posting: See This

Or please atleast be specific to what you want to ask.


Piyush
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
i have searched and got some point related to it.

My question is very simple i want to know why we use of it.

Abhay
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Suppose that you have a servlet which can not service client requests unless you initialize it properly. ServletConfig is used for initializing a particular servlet, and holds the servlet specific init-parameters configurable through deployment descriptor. When the servlet instance is created container creates a corresponding ServletConfig object and calls the servlet's init(ServletConfig) method passing the servletConfig object. Which can be used for obtaining the init-parameter information from it.
ServletConfig is one per servlet.

Similarly if you want that all of your servlets have access to same initialization parameters then instead of copying them in all the servletConfigs you can use ServletContext's init-parameters (context-param). ServletContext is one per web-application. so all the servlets share one ServletContext.

Besides it, ServletContext can also be used for sharing Objects by setting attributes.
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
I got it

Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Config and Servlet Context
 
Similar Threads
Question from David Bridgewater's Book
init parameter.
Servlets
ServletConfig and ServletContext
Servlet context and config