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:
The code inside the <web-apps> not inside the<servlet>
In servlet code:
String name=getServletContext().getInitParameter(“name”);

1 comment:

  1. A simple life is good with me. I don't need a whole lot. For me, a T-shirt, a pair of shorts, barefoot on a beach and I'm happy. See the link below for more info.