DD elements and both can be retrieved by the getInitParameter() method, in the servlet code.<
As explained by Adeel Ansari, here, it depends on what object are you invoking the method getInitParameter() in the servlet code.
All servlets extends from and hence are instance of GenericServlet.
.
DD elements can be retrieved by:
ServletContext context = this.getServletContext();
String paramValue = context.getInitParamter("paramName");
.
DD elements both can be retrieved by:
ServletConfig config = this.getServletConfig();
String paramValue = config.getInitParamter("paramName");
Also note that since GenericServlet class implements ServletConfig interface, your servlet class is also ServletConfig (implies this = this.getServletConfig() ). Hence you can also get DD elements directly by:
String paramValue = this.getInitParamter("paramName");
.
You can try this by having same param-name in both DD elements with different values and then print it in your servlet.