WebServlet annotation not recognized

Wednesday, 27 February 2013 14:46

WebServlet Annotation not working

WebServlet Annotation

Servlet 3.0 provides the @WebServlet annotation to define a servlet, obviating the need for configuration in web.xml . If you are using this annotation available in the Servlet Spec version 3.0 and your favorite application server is not mounting your Servlet as expected. You have probably a problem with the root declaration of your web.xml.

To indicate your Application server you expect to use the Servlet Specifications version 3.0 you should declare in your namespaces the web-app_3_0 xsd in version 3.0 as demonstrated in the following snippet.

So, the root declaration of your web.xml must look like this :

WebServlet annotation


<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
...
</web-app>

If you have any remark or questions feel free to put a comment.If you enjoyed this tutorial and want to promote it don't hesitate to click on

Tags: annotation , servlet , webservlet