• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getServletContext() returning null ???

 
sean cee
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My servlet has the following code in its doGet() method.
String adr = "/xxx/xxx.jsp";
ServletConfig sConf = getServletConfig(); // line1
ServletContext sCont = sConf.getServletContext(); //line2
RequestDispatcher dispatcher= sCont.getRequestDispatcher(adr);//line3
line 1 seems to work fine. (I originally had print statement between each line.. )
but line2 returns null..
'cos I get NullPointerException at line 3.
I am don't know what is wrong...
HELP!!!
 
Satish Kasala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sean,
Can you be more specific about the servlet engine you are using. Some servlet engine doesn't seem to implement the JSDK specs completed. getServletContext() is one of the methods that is primarily based on the servlet engine.
Satish
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sean,
If we had overridden init(ServletConfig config)throws .. {...} method, then we shouldn't forget to call super.init(config); If we miss this line, then latter our servlet can't get hold of ServletConfig object and we will get NullPointerException. Is this your case?
regds
maha anna
[This message has been edited by maha anna (edited December 21, 2000).]
 
sean cee
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks both of you.
Especially Maha, you pinpointed the cause of my problem..
Thanks guys!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic