What is the difference between
and
!?
and
are static parameters which are stored in web.xml file. If you have any data which doesn't change frequently you can store it in one of them.
If you want to store particular data which is confined to a particular servlet scope, then you can use
.Anything you declare inside
is only accessible only for that particular servlet.The init-param is declared inside the
tag.
HelloWorldServlet
HelloWorldServlet
Greetings
Hello
and you can access those parameters in the servlet as follows:
out.println(getInitParameter("Greetings"));
If you want to store data which is common for whole application and if it doesn't change frequently you can use
instead of servletContext.setAttribute()
method of the application context. For more information regarding usage of
VS ServletContext.setAttribute()
have a look at this question. context-param are declared under the tag web-app
.
You can declare and access the
as follows
Country
India
Age
24
Usage in the application either in a JSP or Servlet
getServletContext().getInitParameter("Country");
getServletContext().getInitParameter("Age");