• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

init parameter.

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks every body.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ServletConfig interface has a method getServletContext() which Returns a reference to the ServletContext in which the caller is executing.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic