This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Where does servletContext object get passed onto 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Where does servletContext object get passed onto " Watch "Where does servletContext object get passed onto " New topic
Author

Where does servletContext object get passed onto

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

Hi I know that when a servlet config is created it is passed onto the init method.. However i am a bit confused about servlet context. When a servletcontext is created where is that passed i dont think its the init method as the init accepts only a servlet config object.?? and what happens when both a servlet config and aservlet context are to be passed to a servlet ?? wasnt it suppose to have a method like init(Servletconfig,servletcontext) or something like that ?? I hope someone could help me out clarify this concept... Thanks..


Don’t look where you fall, but where you slipped
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Adam Zedan wrote: what happens when both a servlet config and aservlet context are to be passed to a servlet ?? wasnt it suppose to have a method like init(Servletconfig,servletcontext) or something like that ?? I hope someone could help me out clarify this concept... Thanks..


Adam,

You dont have to do that. you can get the ServletContext from servletconfig.getServletContext() method. Please refer to the java docs.

http://download.oracle.com/javaee/6/api/javax/servlet/ServletConfig.html

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where does servletContext object get passed onto
 
Similar Threads
Servlet context question
init() vs. static {}
ServletContext Null pointer Exception
can any tell what is passed to init() method...
getServletContext() throws NullPointerException