filterRegistration.addInitParameter()
时间: 2024-05-03 09:21:23 浏览: 12
The addInitParameter() method is a method provided by the FilterRegistration interface in the Java Servlet API. This method is used to add an initialization parameter to the filter registration.
The initialization parameters are used to configure the filter during its initialization phase. When a filter is initialized, it can retrieve its initialization parameters by calling the getInitParameter() method of the FilterConfig object.
The addInitParameter() method takes two arguments: a String name, which is the name of the parameter, and a String value, which is the value of the parameter. The method adds the parameter to the filter registration, which can then be accessed by the filter during its initialization.
For example, the following code adds an initialization parameter to a filter registration:
```
FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("myFilter", MyFilter.class);
filterRegistration.addInitParameter("paramName", "paramValue");
```
In this example, a filter registration for a filter named "myFilter" is created using the addFilter() method of the ServletContext object. The addInitParameter() method is then called on the filter registration object to add an initialization parameter with the name "paramName" and the value "paramValue".