0

I am creating a small servlet project to mock an authentication flow. I am performing authentication with a servlet filter sitting in front of a few JSP pages.

To map the urlPatterns captured by the filter, I am using a WebFilter annotation specified as follows:

@WebFilter({"","/gallery.jsp","/welcome.jsp"})

From my understanding, the empty string should catch the root path.

So when I enter localhost:8080/auth-jsp-demo/ into my browser the filter should catch. However, my logs are showing that the filter is not catching the root path.

I am using Tomcat v9 and JDK 11.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
cycler_97
  • 33
  • 1
  • 1
  • 5

1 Answers1

1

Discovered the answer!

It seems the root path is captured in servlets using an empty string in the annotation:

@WebServlet("")

However, for servlet filters the root path is captured with a backslash:

@WebFilter("/")
cycler_97
  • 33
  • 1
  • 1
  • 5