http://docstore.mik.ua/orelly/java-ent/servlet/ch04_01.htm#ch04-33108
The servlet uses the getInitParameter () method to access its init parameters:
public String ServletConfig.getInitParameter(String name)
you define host init-param in web.xml :
<web-app> <servlet> <servlet-name>MyServletName</servlet-name> <servlet-class>com.mycompany.MyServlet</servlet-class> <init-param> <param-name>host</param-name> <param-value>myhost.mycompany.com</param-value> </init-param> </servlet> </web-app>
and get it from Servlet.init() as follows:
public void init() throws ServletException { getServletContext().log("init");
source share