Initialization Parameters in servlet

Initialization parameter represents variable textual information that is define by application developer in web.xml file and is made available to the Servlets by the web server. 


Initialization parameter can be of 2 types:
1- Application specific
2- Servlet specific

1- Application specific:
                                     
Application specific initialization parameters represent textual information that is to be made available to all the Servlet of the application.
<context-param> xml element is used for defining application specific initialization parameter in web.xml.

<web-app>

<context-param>*
<param-name>ParameterName</param-name>
<param-value>ParameterValue</param-value>
</context-param>

------------------------
------------------------

<servlet>*
-------------------------
-------------------------
</servlet>

<servlet-mapping>*
-----------------------
------------------------
</servlet-mapping>

--------------------------------------
--------------------------------------
</web-app>
Note:
* denotes optional


2- Servlet specific:
                             Servlet specific initialization parameter represent information that is to be make available only to a single Servlet for which it is define.
<init-param> sub element of Servlet is used to define Servlet specific initialization parameter in web.xml.

<web-app>
---------------------------
---------------------------
<servlet>*
<servlet-name>UniqueIdentifier</servlet-name>
<servlet-class>ServletClassName</servlet-class>
<init-param>*
<param-name>ParameterName</param-name>
<param-value>ParameterValue</param-value>
</init-param>
</servlet>

<servlet-mapping>*
<servlet-name> UniqueIdentifier</servlet-name>
<url-pattern>UrlPatternRequestedByUser</url-pattern>
</servlet-mapping>

----------------------------
----------------------------
</web-app>
Note:
* denotes optional


Note:
Let us know how server provides these initialization parameters to Servlets?
Answer is, with the help of following interfaces:
1- ServletContext   (Application Scope)
2- ServletConfig     (Servlet Scope)



Comments

Popular posts from this blog

ObjectAid UML Explorer for Eclipse

Login Authentication program (Demonstrate the use RequestDispatcher and its method such as include() and forward() )

Adapter Design Pattern