You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harry Chen <hc...@csee.umbc.edu> on 2000/07/01 02:31:54 UTC
getServletContext() returns null
Hi. I got my servlets start running just fine. I can even do servlet
renaming. But for some reason, everytime i try to call getServletContext()
or getServletConfig() in either doGet() or doPost() method, it always
return NullPointerException.
Any idea? thanks.
Here is a clip of my web.xml file.
-------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"
>
<web-app>
<context-param>
<param-name>Manufacture</param-name>
<param-value>My Company</param-value>
<param-name>Version</param-name>
<param-value>1.0</param-value>
</context-param>
<servlet>
<servlet-name>StoreMgr</servlet-name>
<servlet-class>StoreManagerServlet</servlet-class>
<init-param>
<param-name>StoreName</param-name>
<param-value>Banana Republic</param-value>
</init-param>
</servlet>
</web-app>
- Harry
---
Harry L. Chen
hchen4@cs.umbc.edu
http://www.cs.umbc.edu/~hchen4
University Of Maryland Baltimore County
Public PGP Key is available upon request
Re: getServletContext() returns null
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Harry Chen wrote:
> Hi. I got my servlets start running just fine. I can even do servlet
> renaming. But for some reason, everytime i try to call getServletContext()
> or getServletConfig() in either doGet() or doPost() method, it always
> return NullPointerException.
>
99.9% of the time that means you overrode the init(ServletConfig config)
method without calling
super.init(config)
in your init() method. The best way to avoid this error is to use the init()
method without arguments for your own initialization.
>
> Any idea? thanks.
>
Craig McClanahan