3
votes

I had a Dynamic Web project which had a few @WebServlet annotations, all of which worked fine. I have since switched my Dynamic Web project to a Maven web project. Since doing so, I can't access any of my servlets by what I defined in my @WebServlet annotations. I should also note that some of my servlets are overlay from other Maven projects. Do I have to now define my servlet mappings in the web.xml file?

Thanks

1

1 Answers

3
votes

The Maven story aside, the @WebServlet annotation was introduced in Servlet 3.0. If they are not initialized, then it simply means that either the web application descriptor (the web.xml) is not declared conform Servlet 3.0 or that the target container does not support Servlet 3.0.

You need to verify if your web.xml conforms Servlet 3.0. I.e., the <web-app> root declaration must match that:

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