Servlet 3.0 Annotations
Servlet 3.0引入的annotations:
总结:
Annotation | web.xml equivalent | Component Usage |
---|---|---|
@WebServlet | <servlet> | Servlet classes typically extending javax.servlet.http.HttpServlet |
@WebFilter | <filter> | Servlet Filter class implementing javax.servlet.Filter |
@WebInitParam | <init-param> | Servlet and Filter classes |
@WebListener | <listener> | classes implementing: javax.servlet.ServletContextListener, javax.servlet.ServletContextAttributeListener, javax.servlet.ServletRequestListener, javax.servlet.ServletRequestAttributeListener, javax.servlet.http.HttpSessionListener, javax.servlet.http.HttpSessionAttributeListener |
@MultipartConfig | <multipart-config> | Servlet classes responsible for file upload on multipart/form-data requests |
@ServletSecurity @HttpMethodConstraint @HttpConstraint | <security-constraint> | Servlet classes specifying security constraints |
@HandlesTypes | Not available | Class implementing javax.servlet.ServletContainerInitializer. This is a new pluggability mechanism introduced in Servlet 3.0 |
用@WebServlet注解创建Servlet
可以在web.xml中用@WebServlet
注解创建Servlet组件。
<servlet>
<servlet-name>viewController</servlet-name>
<servlet-class>com.logicbig.servlet.ViewController</servlet-class>
<init-param><param-name>renderer-class-name</param-name>
<param-value>com.logicbig.HtmlRenderer</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
......
<servlet-mapping>
<servlet-name>viewController</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
近期评论