Use the Servlet Filters section and the Filter Mappings section of the web.xml
Visual Editor to add, remove, and view the deployment information of your web application's servlet filters. A filter is a piece of re-usable code that modifies requests to and responses from a servlet.
To deploy a filter, you must register it in the web.xml
file. When you do this, you provide information needed by the server to deploy the filter. For example, you tell the server which types of requests should cause the filter to be deployed.
Before you can register a filter in the web.xml
file, you must create it in the New File wizard or import it from your existing sources. You can use the Configure Filter Deployment panel of the New File wizard to register a filter. If you have not done so, or if you want to modify a registered filter's deployment information, use the Filters view of the web.xml
Visual Editor.
In the Visual Editor, click Filters at the top of the editor to open the Filters view.
First, click Add Filter Element to define the filter element with the following properties.
Element | Description |
---|---|
Filter name |
Specifies the filter's display name, such as LoginFilter .
|
Description |
Specifies a description, such as Performs pre- and post-login operations . |
Filter Class |
Specifies the filter's class, such as MyLoginFlterClass . |
Next, click Add within the filter element and define its initialization parameters.
Element | Description |
---|---|
Param Name |
Specifies the parameter's display name, such as encoding. |
Param Value |
Specifies the parameter's value, such as UTF-8 . |
Description |
Specifies a description, such as Acceptable encoding formats . |
Finally, click Add in the Filter Mappings section to map the filter to servlets or URL patterns to which the filter applies.
Element | Description |
---|---|
Filter Name |
Selects the filter to which the mapping applies, such as LoginFilter .
|
Apply To |
Specifies the URL pattern or servlet to which the filter applies, such as /Authenticate . |
Dispatcher types |
Constrains how the filter will be applied to requests |
Request |
(Default) Only when the request come directly from the client. |
Forward |
Only when the request has been forwarded to a component. |
Include |
Only when the request is being processed by a component that has been included. |
Error |
Only when the request is being processed with the error page mechanism. |
You can select one or more of the dispatcher types above.
Note that when you click Remove at the top of the Servlet Filters section, you remove the filter's deployment information from the web.xml
file, but you do not remove the filter itself. To delete the filter, right-click it in the Projects window and choose Delete.
Related Topics
Developing Applications with NetBeans IDE,
Developing Applications with NetBeans IDE,
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements; and to You under the Apache License, Version 2.0. |