This ServletConfigobject supplies a servlet with information about
This ServletConfigobject supplies a servlet with information about its initialization (init) parameters. These parameters are given to the servlet itself and are not associated with any single request. They can specify initial values, such as where a counter should begin counting, or default values, perhaps a template to use when not specified by the request. In the Java Web Server, init parameters for a servlet are usually set during the registration process. See Figure 3-3. Other servers set init parameters in different ways. Sometimes it involves editing a configuration file. One creative technique you can use with the Java Web Server, but currently by no other servers, is to treat servlets as JavaBeans. Such servlets can be loaded from serialized files or have their init properties set automatically by the server at load time using introspection. See the Java Web Server documentation for more information. Figure 3-3. Setting init parameters in the Java Web Server The ServletConfigobject also holds a reference to a ServletContextobject that a servlet may use to investigate its environment. See Chapter 4, Retrieving Information, for a full discussion of this ability. The server calls a servlet’s destroy()method when the servlet is about to be unloaded. In the destroy() method, a servlet should free any resources it has acquired that will not be garbage collected. The destroy() method also gives a servlet a chance to write out its unsaved cached information or any persistent information that should be read during the next call to init(). A Counter with Init Init parameters can be used for anything. In general, they specify initial values or default values for servlet variables, or they tell a servlet how to customize its behavior in some way. Example 3-3 extends our SimpleCounterexample to read an init parameter (named initial) that stores the initial value for our counter. Example 3-3. A counter that reads init parameters
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services