What is the difference between ServletContext.getInitParameter() and HttpServlet.getInitParameter()?

André Wolf

[Original Question:

I am using Tomcat Web server.I am passing parameter in Web.xml using

But when I am calling getInitParameter("server") in init method it is returning null value. How to resolve this? ]

The <context-param> tag is used to set an init parameter for the whole application context, it is accessible by all Servlets and JSPs. You have to use getInitParameter() of javax.servlet.ServletContext, not the similar method found in HttpServlet. Just try the following method call in your servlet, it should return the correct parameter:


Alternatively, you can set an init parameter for a specific Servlet, it will only be accessible by this Servlet:



To retrieve this parameter you just call getInitParameter() in your servlet.