So I have a class that extends HttpServlet and I was trying to access variables set in different class that has implemented ServletContextListener.
However the following line of code in the class that extends HttpServlet is giving me the NullPOinterException:
SomeObject x = getServletContext().getAttribute("x");
I don't understand why this is happening. Any ideas?
可能是您在Servlet类中重写了init(ServletConfig cfg)方法,并且没有调用super.init(cfg)进行标准设置,从而导致上下文为空。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.