I need to retrieve init-param value from xml to Servlet i used following code
LoginServlet
&
um... it should work. Are you calling the code in LoginServlet? And the
<servlet-class>LoginServlet</servlet-class>
is not in any package?
I can't see a single reason, why you have to override your init(ServletConfig sc)
method, since you can always get your ServletConfig
by calling your inherited getServletConfig()
method.
System.out.println(getServletConfig().getInitParameter("jdbcDriver"));
If you have custom initialization work to do, override the no-arg init() method, and forget about init(ServletConfig). Is it ok to call getServletConfig() method inside the no-arg init() method? Yes, an instance of ServletConfig has already been saved by superclass GenericServlet.
http://javahowto.blogspot.com/2006/06/common-mistake-in-servlet-init-methods.html
It is always good to use packages for classes. It enables clear demarcation.