• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getServletContext null pointer

 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic