Sometimes it is useful to pass some initialization parameters to a servlet; that way we can make sure the servlet behaves differently based on the parameters that are sent to it. For example, we may want to configure a servlet to behave differently in development and production environments.
In the old days, servlet initialization parameters were sent via the <init-param> parameter in web.xml. As of servlet 3.0, initialization parameters can be passed to the servlet as the value of the initParams attribute of the @WebServlet annotation. The following example illustrates how to do this:
package net.ensode.javaee8book.initparam; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.annotation.WebInitParam; ...