WebInitParam
WebInitParam is a Java annotation in the javax.servlet.annotation package used to declare an initialization parameter for a servlet or filter when using annotation-based configuration in the Java Servlet API. It defines two elements, name and value, both strings. WebInitParam is intended to be used inside the initParams attribute of @WebServlet or @WebFilter annotations to provide per-servlet or per-filter initialization data without relying on web.xml.
Usage involves supplying one or more WebInitParam entries within a servlet or filter annotation. For example:
@WebServlet(urlPatterns = {"/example"}, initParams = {
@WebInitParam(name = "configPath", value = "/WEB-INF/config.xml")
})
Retrieval of these parameters is done through the servlet’s configuration. In the servlet’s init method you
public void init(ServletConfig config) throws ServletException {
String path = config.getInitParameter("configPath");
}
Compatibility and scope: WebInitParam was introduced with Servlet 3.0 (Java EE 6) to support annotation-based configuration.
See also: WebServlet, WebFilter, ServletConfig, Servlet initialization parameters.