Init Param And Context Param

Init Param is used to pass initialization parameter to the particular servlet. This parameters can be used to customize the behavior of a servlet at the time of it;s initialization. init parameters are stored inside an object of ServletConfig and every servlet has one instance of ServletConfig, which is created at the time of servlet initialization.

Context Param is used to define global or application scope parameter for the application which can be shared by all the available servlets inside the jsp/servlet container. these parameters can be used to customize the behavior of web application. context parameters are stored an object of ServletContext, which is created at the time of deploying the web appplication on server.

 Example of init-param for servlet :-

We have define a servlet "MagicServlet" which mapping is done in web.xml file. it is taking two initialization parameters which are email and color and same is explained below.
init-param


init-param-out


Real Example of init-param from spring mvc popular web framework.
init-param-example