Consider the definition below in web.xml
<servlet> <servlet-name>HelloWorld</servlet-name> <servlet-class>TestServlet</servlet-class> <init-param> <param-name>myprop</param-name> <param-value>value</param-value> </init-param> </servlet>
You can see that init-param is defined inside the servlet element. This means that it is available only to the servlet under the declaration, and not to other parts of the web application. If you want this parameter to be available to other parts of the application, say, JSP, this should be explicitly passed to JSP. For example, passed as request.setAttribute (). It is very inefficient and difficult to code.
So, if you want to access global values ββfrom anywhere in the application without explicitly passing these values, you need to use the Init context parameters.
Consider the following definition in web.xml
<web-app> <context-param> <param-name>myprop</param-name> <param-value>value</param-value> </context-param> </web-app>
This context parameter is available to all parts of the web application and can be retrieved from the Context object. For example, getServletContext (). GetInitParameter ("dbname");
From the JSP, you can access the context parameter using an implicit application object. For example, application.getAttribute ("dbname");
SMA Feb 08 '15 at 10:43 2015-02-08 10:43
source share