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 i开发者_运维技巧f I try to use "index" instead, it doesn't work.
Can someone please help?
Cheers, M.
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.
精彩评论