Sometimes, you will need to define some parameters for your servlet that go beyond local variables—initParams is the place to do it. Consider the following code:
@WebServlet(name = "InitConfigServlet", urlPatterns =
{"/InitConfigServlet"},
initParams = {
@WebInitParam(name = "key1", value = "value1"),
@WebInitParam(name = "key2", value = "value2"),
@WebInitParam(name = "key3", value = "value3"),
@WebInitParam(name = "key4", value = "value4"),
@WebInitParam(name = "key5", value = "value5")
}
)
The @WebInitParam annotation will handle them for you and these parameters will be available for the server through the ServletConfig object.