File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init parameter.

 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext is inside the ServletConfig, so there's no reason to pass it to a Servlet separately.
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks every body.
 
kalle suresh
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletConfig interface has a method getServletContext() which Returns a reference to the ServletContext in which the caller is executing.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic