• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getServletContext() returning null

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to excecute the following code it gets compiled but when i call that servlet i am getting null pointer exception.

the code is as follows.....


thanks in advanced.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you calling the Servlet? ie have you provided a servlet mapping?
 
Sameer Damle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i have provided mapping for the servlet


i am calling the sevlet using the url

http://172.20.44.85:7001/sameer/Versionservlet
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have overridden init(ServletConfig) so you should store the servletConfig somewhere, or call the parent's init method.

In your init():
Either ctx = cfg.getServletContext();
Or super.init(cfg);


Overriding the init() method will prevent the default mechanism, so HttpServlet won't store the ServletConfig for you. That's why getServletContext() will cause NullPointerException.
[ January 26, 2006: Message edited by: Satou kurinosuke ]
 
Sameer Damle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks satou...

i just called super.init() from the overridden init()....

that solved the purppose...

thanks once again for prompt help....
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D'oh, nice catch.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sameer Damle

Just update the servlet FAQ. Take a look at it to have a better understanding of init() and init(ServletConfig config).

I request moderators to erase the question marks and make it look better.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:You have overridden init(ServletConfig) so you should store the servletConfig somewhere, or call the parent's init method.

In your init():
Either ctx = cfg.getServletContext();
Or super.init(cfg);


Overriding the init() method will prevent the default mechanism, so HttpServlet won't store the ServletConfig for you. That's why getServletContext() will cause NullPointerException.
[ January 26, 2006: Message edited by: Satou kurinosuke ]



Thank you very much Mr Verré.
Four years later, you always helps someone else.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic