Some servlets and filters require initialization parameters. The init-param element within a filter or servlet definition element contains initialization parameters for that filter or servlet instance. These are distinct from context parameters, discussed in Section 4.7. Each init-param contains a param-name element and a param-value element. Although the servlet container does not interpret the contents of the param-name and param-value, the contents of these elements must be legal XML. If the web.xml file is in UTF-16, the servlet container transcodes the contents of the param-name and param-value to UTF-8.
The web.xml snippet below defines two initialization parameters for a servlet, greeting and fontsize, and two for a filter, request and response.
<servlet> <servlet-name>helloWorld</servlet-name> <servlet-class>hello.createHelloWorld</servlet-class> <init-param> <param-name>greeting</param-name> <param-value>Hello, World!</param-value> </init-param> <init-param> <param-name>fontsize</param-name> <param-value>14</param-value> </init-param> </servlet> <filter> <filter-name>GenericFilter</filter-name> <filter-class>org.apache.tester.WrapperFilter</filter-class> <init-param> <param-name>request</param-name> <param-value>generic</param-value> </init-param> <init-param> <param-name>response</param-name> <param-value>generic</param-value> </init-param> </filter> |
If a definition contains two or more parameters with the same name, the container will present one param-value and ignore the others.
Section 6.7 describes the interface a servlet or filter uses to read initialization parameters.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.