JSP details-New Features of Servlet3.0
Added comments for new features of Servlet3.0
Through annotations, you do not need to configure Servlet or filter in web. xml. Comments added to Servlet3.0 include @ WebServlet, @ WebListener, and @ WebInitParam. The following describes
1. @ WebServlet
@ WebServlet annotation is used to define Servlet components before Servlet class declaration. With this annotation, you do not need to configure the Servlet in web. xml. @ Attributes of WebServlet Annotations:
Attribute name |
Type |
Description |
Name |
String |
Specify the Servlet name attribute, which is equivalent . If no display is specified, the Servlet value is the fully qualified name of the class. |
Value |
String [] |
It is equivalent to the urlPatterns attribute, but the two cannot be used at the same time. |
UrlPatterns |
String [] |
Specifies the URL matching mode for a group of servlets. Equivalent Tag |
LoadOnStartup |
Int |
Specify the Servlet loading sequence, which is equivalent Tag |
InitParams |
WebInitParam [] |
Specify a set of Servlet initialization parameters, which is equivalent Tag |
AsyncSupported |
Boolean |
Specifies whether the Servlet supports asynchronous operations, which is equivalent |
Description |
String |
Servlet description, equivalent Tag |
DiaplayName |
Sting |
Servlet display name, usually used with tools, is equivalent Tag |
2. @ WebFilter
@ WebFilter annotation is used to declare a filter. The annotation will be processed by the container during deployment, and the container will deploy the corresponding class as a filter according to the specific configuration. @ WebFilter attribute list:
Attribute name |
Type |
Description |
FilterName |
String |
Specify the name attribute of the filter, which is equivalent |
Value |
Sring [] |
It is equivalent to the urlPatterns attribute, but the two cannot be used at the same time. |
UrlPatterns |
String [] |
Specify the URL matching mode of the filter, which is equivalent Tag |
ServletNames |
String [] |
Specify the Servlet to which the filter will apply. It is the value of the name attribute in @ WebServlet or in web. xml. Value |
InitParams |
WebInitParam [] |
Specifies the initialization parameters of a set of filters, which is equivalent Tag |
AsyncSupported |
Boolean |
Whether the declared filter supports asynchronous operations is equivalent |
Description |
String |
The description of the filter, which is equivalent |
DisplayName |
String |
The display name of the filter, usually used with tools, is equivalent Tag |
DispatcherTypes |
DispatcherType |
Specify the forwarding mode of the filter, including ASYNC/ERROR/FORWADR/INCLUDE/REQUEST |
3. @ WebListener
This annotation is used to declare listeners and act as listener classes for various Web events in a given Web application context. You can use @ WebListener to mark a class that implements ServletContextListener/ServletContextAttributeListener/ServletRequestListner/ServletRequestAttributeListener/HttpSessionListener/HttpSessionAttributeListener. @ WebListener the annotation has a value attribute, which is an optional attribute used to describe listener information. You do not need to configure this annotation in web. xml. Tag
4. @ WebInitParam
This annotation is equivalent And Of Sub-tag. This annotation cannot be used independently. It must be used with @ WebServlet or @ WebFilter. This parameter is used to specify initialization parameters for the Servlet or filter. Attributes contained in the @ WebInitParam annotation:
Attribute name |
Type |
Optional |
Description |
Name |
String |
No |
The name of the specified parameter, which is equivalent |
Value |
String |
No |
The value of the specified parameter, which is equivalent |
Description |
String |
Yes |
The parameter description is equivalent |