In this article, we will see how to use servlets and handle global init parameters in Java web.
Servlet mapping is used for addressing the web container that java servlet will be used for a url requested by client. It maps url or url patterns to servlets. When browser requests, servlet container decides to which application it calls for request.
In Servlet mapping in code behind, we take url query string as parameter into our JSP. In further level, if we want to init a parameter at initialization time, we can set our parameter in code behind.
Earlier article we had covered how to keep init parameters, their scope is servlet level. If we want to convert them to application level, we can use context parameters.
Lets see it in the code.
@WebServlets { ... initParams ... }
Lets see it in a java example.
In above example, we mapped a servlet added global init parameters to our web.xml and we use in code behind.