Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference b/w <context-param> and <init-param>

DD elements <context-param> and <init-param> both can be retrieved by the getInitParameter() method, in the servlet code.

Now the question is, how does it differentiate <context-param> and <init-param>?

like image 339
giri Avatar asked Jan 15 '10 06:01

giri


People also ask

What is context param?

Context Parameter is a variable that is replaced by a predefined or calculated value during monitoring or load testing. Value could be assigned directly, taken from a file, calculated in a script, or be a result of the execution of another task.

What is context param in servlet?

The context-param element, subelement of web-app, is used to define the initialization parameter in the application scope. The param-name and param-value are the sub-elements of the context-param. The param-name element defines parameter name and and param-value defines its value.

What are context initialization parameters?

Context Initialization parameters are the parameter name and value pairs that you can specify in the deployment descriptor file (the web. xml file). Here you can specify the parameters that will be accessible to all the servlets in the web application.

What is context param in web xml spring?

In a spring web application, contextConfigLocation context param gives the location of the root context. Your config is strange, for a spring-mvc application, because by default, servletname-servlet. xml (where servletname is the name of a DispatcherServlet servlet) is the child application context for the servlet.


1 Answers

Servlet init parameters are for a single servlet only. Nothing outside that servlet can access that. It is declared inside the <servlet> tag of Deployment Descriptor, on the other hand context init parameter is for the entire web application. Any servlet or JSP in that web application can access context init parameter. Context parameters are declared in a tag <context-param> directly inside the <web-app> tag.

The methods for accessing context init parameter is

getServletContext().getInitParameter("name");  

whereas the method for accessing servlet init parameter is

getServletConfig().getInitParameter("name"); 
like image 168
Adeel Ansari Avatar answered Sep 24 '22 15:09

Adeel Ansari