What is context parameter?

The context parameters are available for the entire web application, not just a single servlet. So any servlet and jsp has access to context params.

First container reads the DD and creates a name/value pair for each context param. Container creates a new instance of ServletContext. Container gives the ServletContext a reference to each name/value pair of the context init parameters. Every servlet,jsp deployed as part of a single web app has access to that same servlet context. If the web app is distributed there is one ServletContext per JVM.

In web.xml:
<web-apps>
<context-param>
<param-name>name</param-name>
<param-value>bhabanipattanayak</param-value>
</context-param>
</web-apps>
The code inside the <web-apps> not inside the<servlet>
In servlet code:
String name=getServletContext().getInitParameter(“name”);

No comments:

Post a Comment