The Servlet 3.0 specification defines a number of annotation types which can be used to declare servlets, filters, listeners, security constraints and other metadata within Java source files as an alternative mechanism to XML declaration in web deployment descriptor file (web.xml).

The following table lists all annotation types available in Servlet 3.0. Click on an annotation type to see its syntax, attributes description and code examples:

Annotation type

Equivalent XML elements in web.xml

 

@HandlesTypes

 

 

None

 

@HttpConstraint

 

 

<http-method-exception>

 

@HttpMethodConstraint

 

 

<http-method>

 

@MultipartConfig

 

 

None

 

@ServletSecurity

 

 

<security-constraint>

 

@WebFilter

 

 

<filter>, <filter-mapping>

 

@WebInitParam

 

 

<init-param>

 

@WebListener

 

 

<listener>

 

@WebServlet

 

 

<servlet>, <servlet-mapping>

 

All the annotation types listed in the above table are declared in the package javax.servlet.annotation.

 

Other Java Servlet Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment