permaculture playing cards*
The moose likes Servlets and the fly likes getServletContext() returning null ??? 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 » Java » Servlets
Bookmark "getServletContext() returning null ???" Watch "getServletContext() returning null ???" New topic
Author

getServletContext() returning null ???

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
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!!!


Sean <br />SCJP2, SCJP2p1.4, SCWCD
Satish Kasala
Greenhorn

Joined: Dec 19, 2000
Posts: 16
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

Joined: Jan 31, 2000
Posts: 1467
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

Joined: Oct 24, 2000
Posts: 115
Thanks both of you.
Especially Maha, you pinpointed the cause of my problem..
Thanks guys!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: getServletContext() returning null ???
 
Similar Threads
a difficult problem in JSTL
when will it be Garbage collected?
a constructor calls another constructor. Where ?
Issue on arrays
PrintWrite close() does not catches Exception