Tuesday 8 April 2014

Context Initialization Parameters

Context Initialization Parameters

  • So far we discussed, Servlet Container supports to store startup and configuration information for a Servlet as initialization parameters (init parameters).
  • init parameters are configured specific to the Servlet configured in the deployment descriptor file, means these data can be retrieved only one servlet
  • But I want to configure data that has to be retrieved into all or more than one servlet.
  • For example my web application contains two servlets , login and registration, and you want the Driver class name and the JDBC URL of both Servlets to establish a connection, for this situation we can implement by using the context initialization parameters (Context init parameters), which are provided under Servlet specification.
This type of parameters are accessible to all the web components in this application.

How to declare the context init parameters?

The following tag is used as a direct child of <web-app> in web.xml to do this:


Syntax:

 <context-param>
     <param-name>parameter name</param-name>
     <param-value>parameter value</param-value>
</context-param>


  • this is not in side servlet, this is out side servlet
  • Annotations style is not supported for configuring this requirement.




No comments:

Post a Comment