0

I'm stuck with this problem and I can't find a solution for it anywhere, so any ideas are welcome.

I want to execute some code on a @WebServlet (javax.servlet.annotation.WebServlet) before it loads my index.jsp. For that I added "/" to the urlPatterns. This does what it's expected in the index.jsp, but it doesn't load my css or image paths any more. The problem is the "/" makes it include all other files in these urlPatterns, but if I try to use "index" instead, it doesn't work.

Can someone please help?

Cheers, M.

adarshr
  • 61,315
  • 23
  • 138
  • 167
Monica
  • 51
  • 1
  • 3

1 Answers1

1

Just use an url-pattern which exactly matches /index.jsp.

@WebServlet(urlPatterns = { "/index.jsp" })

Unrelated to the concrete question, I wonder if you can't better use a ServletContextListener (which is annotable using @WebListener). This is certainly true when your sole functional requirement is to preload/preinitialize some application-wide data on server's startup, regardless of the first-opened webpage.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555