Difference between @WebServlet ("/") and @WebServlet ("/ *")


When creating a servlet , what is the difference between using the following patterns to define the URL? "/" and "/*" , using annotations and the specification 3.1.



Which of these URL patterns should I use if I want my servlet to respond to any request? Are they the same or is there a difference between them?

asked by nullptr 23.07.2017 в 16:56

1 answer


The difference is that @WebServlet("/") will only respond to something like unaweb.com or unaweb.com/ .

While @WebServlet("/*") will respond to

  • unaweb.com/paginauno
  • unaweb.com/unapagina

  • unaweb.com/ndjdjd

In summary you can put the string that is after the diagonal.

So you want it to respond to any pattern use the second option.

answered by 23.07.2017 в 17:27