aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes init parameter. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "init parameter." Watch "init parameter." New topic
Author

init parameter.

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Container passes the ServletConfig to the init() method of the Servlet at the initialization time. But how the container pass the ServletContext to which servlet's which method, because it is a application based? I mean how container initialize ServletContext?

Any one help me?


SCJP-1.5<br />SCWCD-1.4
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

ServletContext is inside the ServletConfig, so there's no reason to pass it to a Servlet separately.


A good workman is known by his tools.
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
So whenever you want to use ServletContext init parameter in your Servlet you have to initialize the Servlet by running it's init(ServletConfig) method. If container already initialized the Servlet (which needs ServletContext init parameter)then you can access ServletContext init parameter directly.Correct me if I am wrong.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

you have to initialize the Servlet by running it's init(ServletConfig) method.

How would you do that ? Where would you take the ServletConfig from ? No, the container calls the init method. You can't use the ServletContext until the servlet has been initialized by the container.


[My Blog]
All roads lead to JavaRanch
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Whenever you want ServletContext init parameter container first initialize the Servlet, so you get ServletConfig then you get ServletContext init parameter. Correct me if I am wrong.
S Vilish
Ranch Hand

Joined: Feb 06, 2007
Posts: 39
When web app is loaded in memory by container by using web.xml of the app , servletContext Object is created and becomes avaible to all servlets and JSPs in the app. Now when a servlet is loaded in memory by container, it creates ServletConfig object and pass it to the servlet. This object contains the ServletContext Object.

Vilish
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks every body.
kalle suresh
Ranch Hand

Joined: Nov 20, 2007
Posts: 48
ServletContext is inside the ServletConfig

I have one doubt here. Servlet Context is common to all servlets. Servlet Config is per servlet. In that case how the Servlet Context is inside the Servlet Config?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What prevents you(ServletConfig) and I(ServletConfig) from using the same train(ServletContext) ? The train doesn't care who's riding in, but you know which train you're using, don't you ? Does it make sense to make ServletContext accessible from the ServletConfig ?
S Vilish
Ranch Hand

Joined: Feb 06, 2007
Posts: 39
ServletConfig interface has a method getServletContext() which Returns a reference to the ServletContext in which the caller is executing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init parameter.