|
Servlet ConfigurationWhen a Servlet is first started by the servletrunner or a webserver, it can be passed a set of parameters to the servlet. These parameters are stored in a file which is accessed by your servlet engine. The format varies for different servlet engines. JSDK 2.0 : Servlet Runner & Apache JServUnder the servletrunner, these parameters can be specified in a file called servlet.properties, such as that shown below. Under apache, the name of the file
will depend on your configuration, but is likely to be servlet.properties or zone.properties. If the servlet.properties file is placed in the same directory as the root of the servlet tree, then it will be read automatically when the servletrunner is invoked.
Alternatively, you can use the -s tag to explicitly tell the servletrunner where to find the properties. eg : JSDK 2.1 : JSDK ServerThe JSDK server reads all the config parameters from the WEB-INF/servlets.properties file. In order to use properties, the servlet has to be 'mapped' and then the mapped
servlet can be given parameters. eg :
This will set up a mapped servlet called 'name', when this servlet is accessed through the URL 'http://localhost:5000/servlet/name' (or equivalent), it will be passed the parameters specified in the initparams property. If you try to access the servlet directly (ie with the class name), these parameters will be ignored. What happens ?For the above examples, when the servlet engine is invoked, a parameter called 'MESSAGE' with the value 'Hello' is sent to the MyNameServlet, packaged as a ServletConfig object. All Servlet enabled webservers should be capable of passing startup parameters in the same way. In order to recieve this data, the servlet needs to implement an additional method which is used to receive this configuration information. This modification is shown below.
This servlet adds the 'init' method which receives the 'ServletConfig' object. The parameters held within this object can then be simply read with the 'getInitParameter' method.
| ||||||
|
Tims Home Page | Page last modified : 19 May 2003 | |||||||