How to retrieve <servlet><init-param> value from web.xml in Servlet?
12,597
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"));
Author by
Anand
Updated on June 05, 2022Comments
-
Anand about 2 years
I need to retrieve init-param value from xml to Servlet i used following code
<servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>LoginServlet</servlet-class> <init-param> <param-name>jdbcDriver</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </init-param> </servlet>
servlet code
public void init(ServletConfig config) throws ServletException { super.init(config); System.out.println(config.getInitParameter("jdbcDriver")); }
But It displayed null .. could any one help me to do that . thanks in advance