Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes passing ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "passing ServletContext" Watch "passing ServletContext" New topic
Author

passing ServletContext

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

How can I get ServletContext object form ServletConfig?
Is ServletContext object passed somehow?


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

Did you bother to even look at the javadoc?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Yes, I did read it. I try to ask smart guestions
I know that there is a method getServletContext() in ServletConfig but how does that reference appear in ServletConfig?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

If you know already know how to get it, then I do not understand the question.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

Lukas Smith wrote:I know that there is a method getServletContext() in ServletConfig but how does that reference appear in ServletConfig?

The question is not very much clear, but the container puts the ServletContext in the ServletConfig object...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

ServletConfig is passed to init(...) method of a servlet. How is ServletContext passed to ServletConfig object?
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

The container can call the ServletConfig.setServletContext to add the ServletContext object to ServletConfig. The container may use any other technique like reflection but whatever it is, the container has the responsibility of doing this work...
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

OK, thanks Ankit. It is clear.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: passing ServletContext
 
Similar Threads
ServletContext object
ServletContext Doubt / Poll
ServletContext Object?
What is the name of the object that is created/maintained by the Servlet Container and contains all
Context Path Issue in Struts