In this article, we will see how to use servlets and handle init parameters within requests in Java.
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.
In this part, we will cover how to keep it in web.xml, earlier article we had covered how to keep init parameters in code behind.
Lets see it in the code.
@WebServlets { ... initParams ... }
Lets see it in a java example.
In above example, we mapped a servlet added init parameters to our web.xml and we use in code behind. Notice that we created an init method for taking parameter first, then we get its value in doGET method.