This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Problem with ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with ServletContext" Watch "Problem with ServletContext" New topic

Problem with ServletContext

Aleks V. Pascoal
Ranch Hand

Joined: Apr 21, 2002
Posts: 73
Why i can't use the getServletContext twice in the same Servlet? I used it in the init then in the doGet. The second time returns null.
Can anyone help me with that?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
Which init method did you use? If you used the one that takes a ServletConfig object as a parameter you have to call super.init(config). It is the init method that gets the ServletContext and makes it available.
If that's not the case then post some of our code that calls the methods and also your init method.

I agree. Here's the link:
subject: Problem with ServletContext
It's not a secret anymore!