user1370422
user1370422

Reputation:

GetServletContext returning null in a class that extends HttpServlet

Ther is class that extends HttpServlet and trying to access variables set in different class

The following line of code in the class that extends HttpServlet is throwing a NullPOinterException:

SomeObject x =  getServletContext().getAttribute("x");

Ideas?

Upvotes: 0

Views: 1911

Answers (1)

Udo Klimaschewski
Udo Klimaschewski

Reputation: 5315

Probably, you have overridden the init(ServletConfig cfg) method in your Servlet class and did not call the super.init(cfg) to do the standard setup stuff, resulting in an empty context.

Upvotes: 1

Related Questions