开发者

Webservlet urlpatterns for index.jsp

开发者 https://www.devze.com 2023-02-16 13:54 出处:网络
I\'m stuck with this problem and I can\'t find a solution for it anywhere, so any ideas are welcome.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消