Skip to main content
Minor updates and corrections.
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108

2) There are two types of two types of init parametersinit parameters available. Another quote from "Head First Servlets and JSP" (emphasis mine):

There are context init parameters (defined in <context-param> element) and servlet init parameters (defined in <init-param> element). They are both referred to as init parameters, although defined in defferentdifferent elements.

  • Context init parameters are available to any servlet or JSP that are part of the current web app.

  • Servlet init parameters are available to only the servlet for which the <init-param> was confguredconfigured.

  • Context init parameters are defined within the <web-app> element.

  • Servlet init parameters are defined within the <servlet> element for each specific servlet.

Accessing **context init parameter** in a servlet:getServletContext().getInitParameter(“email”);

Accessing servlet init parameter in a servlet for which it was defined in the deployment descriptor:
getServletConfig().getInitParameter("name");

  • Accessing context init parameter in a servlet:
    getServletContext().getInitParameter(“email”);
  • Accessing servlet init parameter in a servlet for which it was defined in the deployment descriptor:
    getServletConfig().getInitParameter("name");

And there is also Enumeration<String> getInitParameterNames() method for both ServletContext and ServletConfig to get all init parameters.


Hope this will help you.

2) There are two types of init parameters available. Another quote from "Head First Servlets and JSP" (emphasis mine):

There are context init parameters (defined in <context-param> element) and servlet init parameters (defined in <init-param> element). They are both referred to as init parameters, although defined in defferent elements.

  • Context init parameters are available to any servlet or JSP that are part of the current web app.

  • Servlet init parameters are available to only the servlet for which the <init-param> was confgured.

  • Context init parameters are defined within the <web-app> element.

  • Servlet init parameters are defined within the <servlet> element for each specific servlet.

Accessing **context init parameter** in a servlet:getServletContext().getInitParameter(“email”);

Accessing servlet init parameter in a servlet for which it was defined in the deployment descriptor:
getServletConfig().getInitParameter("name");

And there is also Enumeration<String> getInitParameterNames() method for both ServletContext and ServletConfig to get all init parameters.


Hope this will help you.

2) There are two types of init parameters available. Another quote from "Head First Servlets and JSP" (emphasis mine):

There are context init parameters (defined in <context-param> element) and servlet init parameters (defined in <init-param> element). They are both referred to as init parameters, although defined in different elements.

  • Context init parameters are available to any servlet or JSP that are part of the current web app.

  • Servlet init parameters are available to only the servlet for which the <init-param> was configured.

  • Context init parameters are defined within the <web-app> element.

  • Servlet init parameters are defined within the <servlet> element for each specific servlet.

  • Accessing context init parameter in a servlet:
    getServletContext().getInitParameter(“email”);
  • Accessing servlet init parameter in a servlet for which it was defined in the deployment descriptor:
    getServletConfig().getInitParameter("name");

And there is also Enumeration<String> getInitParameterNames() method for both ServletContext and ServletConfig to get all init parameters.

Added related link.
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108

Accessing servlet init parameter in a servlet for which it was defined in DDthe deployment descriptor:
getServletConfig().getInitParameter("name");

Accessing servlet init parameter in a servlet for which it was defined in DD:
getServletConfig().getInitParameter("name");

Accessing servlet init parameter in a servlet for which it was defined in the deployment descriptor:
getServletConfig().getInitParameter("name");

Fixed grammar; updated a link.
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108

OK, besides the JB NizetNizet's comment here are a few suggestions.

An alternative way of getting servlet init parameter is using a method defined in the abstract class GenericServletGenericServlet:
public String getInitParameter("name"String name);
This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.

OK, besides the JB Nizet comment here are a few suggestions.

An alternative way of getting servlet init parameter is using method defined in the class GenericServlet:
getInitParameter("name");
This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.

OK, besides the JB Nizet's comment here are a few suggestions.

An alternative way of getting servlet init parameter is using a method defined in the abstract class GenericServlet:
public String getInitParameter(String name);
This method is supplied for convenience. It gets the value of the named parameter from the servlet's ServletConfig object.

Minor improvement for better readability
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
added 127 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
added 127 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
[Edit removed during grace period]
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
edited body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
deleted 2 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
added 389 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
added 15 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
added 494 characters in body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
edited body
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading
Source Link
informatik01
  • 16.3k
  • 11
  • 77
  • 108
Loading