Why does config.getInitParameter(String) always return null in the following code example?
public void init(ServletConfig config) throws ServletException
{
super.init(config);
filename = config.getInitParameter("addressfile");
This is web.xml file
<servlet>
<servlet-name>ListManagerServlet</servlet-name>
<servlet-class>savva.listmanagerservlet.ListManagerServlet</servlet-class>
<init-param>
<param-name>addressfile</param-name>
<param-value>d:\temp\demo.txt</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ListManagerServlet</servlet-name>
<url-pattern>/ListManagerServlet</url-pattern>
</servlet-mapping>
UPD: Eclipse EE Indigo, Java 1.6, Tomcat 7.0
The canonical way is to just use the inherited
GenericServlet#getInitParameter()in the argumentlessinit()method (and remove anyinit(config)method).If that still doesn’t work, then your
web.xmlis not properly been deployed, or you have a typo in the parameter name, or you actually accessed a different instance variable thanfilenameto use/test it.