File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes getServletContext null pointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getServletContext null pointer" Watch "getServletContext null pointer" New topic
Author

getServletContext null pointer

Al Hollis
Ranch Hand

Joined: Dec 12, 2005
Posts: 60
Please can ya help me out yet again wise ones

I have two servlets, and 1 bean. In one servlet i set the values of the bean and store them in the servlet context. In another servlet i try to get the ServletContext back, But it allways returns a null pointer error...

Here is the code, thanks in advance for help.

setUp.java


getConnection.java


And finally the bean



If you got this far, thanks for looking
[ December 24, 2005: Message edited by: Bear Bibeault ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
1. are both servlets in the same "Web application"?
are both defined in one web.xml?
2. you left out one crucial bit of information - which reference is null?
is it bob? if so maybe your init method is at fault and you are missing the ServletConfig reference
is it dbParam? if so maybe the two servlets are not really sharing the same context
3. are you relying on the "invoker" servlet at any point? See this Ranch FAQ if you are.
Bill
Al Hollis
Ranch Hand

Joined: Dec 12, 2005
Posts: 60
well ive kinda sorted the problem now using instance rather that servlet context to store it...

However i would like to switch back to servlet context as my tutor seems to prefer this

Bob is the place where it throws a null reference back at me,
They are both in one web application, i havnt used any init meathods so not sure how that can be the case. Its really got me stumped, ohh and no invoker meathod either...

Thanks for looking!
[ December 24, 2005: Message edited by: Al Hollis ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

Bob is the place where it throws a null reference back at me
This is rather ambiguous. Are you saying that the variable "bob" contains null? Surely not. Why don't you tell us which line of code throws the exception? Your stack trace should tell you the exact line number.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getServletContext null pointer