This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Questions about ServletContext and ServletConfig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Questions about ServletContext and ServletConfig" Watch "Questions about ServletContext and ServletConfig" New topic
Author

Questions about ServletContext and ServletConfig

David Jones
Greenhorn

Joined: Dec 26, 2003
Posts: 27
Hi all,

I have some questions about ServletContext and ServletConfig:

On HFSJ, page 151:
"By the time the servlet is running service methods, it's got a ServletConfig"

(Q1) Does this mean that ServletConfig can only be available in service() method (i.e. after init() method)?
(Q2) How about the ServletContext? Is ServletContext also ONLY be available in service() method (i.e. after init() method)?

On HFSJ, page 308:
"jspInit() called from the servlet's init() method, so by the time jspInit() runs there is a ServletConfig and ServletContext available to the servlet"

(Q3) As HFSJ mentioned, we can use ServletConfig and ServletContext in jspInit() method (i.e. can use them before _jspService() method, not like Servlet that only be avilable in service() method). Is this because the init() method of the generated servlet has already been executed and so ServletConfig and ServletContext are available in jspInit() method (since init() called jpsInit())?

Thanks
David
singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
hi,
Let me try to clarify your doubts : there are two version init method:
1)init(ServletConfig config) in Servlet [life cycle method]
2)init() in GenericServlet (provide for u to override)

When the container intializes the servlet it calls init (1 version) .This init after successful initialization calls init (2 version).

So by the time init() is called ServletConfig is already avaialble.

ServletConfig holds the reference to ServletContext(offcource u can also get it through getServletContext() of GenericServlet class).

Same is true with the jsp also.

i hope i have clarified ur doubts.
Please let me know if i m wrong

regards

-santosh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions about ServletContext and ServletConfig
 
Similar Threads
Calling jspInit() from servlet's init();
servlet lifecycle question
jspInit()
jspInit()
Regarding the init() methods