0

我目前有一个带有以下注释的主控制器 servlet:

@WebServlet(name="ControllerServlet", urlPatterns={"/", "/home"})

我的项目目录下有 .js 和 .css 文件/resources,我的 .jsp 文件引用了这些文件,并且链接被发送到我不想要的主控制器。我制作了第二个 servlet 来处理带有 nn 注释的 .js .css 文件:

@WevServlet(name="ResourceServlet", urlPatterns={"/resources"})

希望它能接收来自我的 .jsp 文件的请求,但 ControllerServlet 仍在接收它们。如何使 /resources url 定向到我的 ResourceServlet?

4

1 回答 1

1

The url pattern / matches anything that isn't matched by the other mappings. If you have

@WebServlet(name="ResourceServlet", urlPatterns={"/resources"})

then a request to, eg. localhost:8080/context/resources will be handled by your ResourceServlet, but a request to localhost:8080/context/resources/somescript.js won't because it doesn't match ResourceServlet's url pattern. Therefore, ControllerServlet will handle it.

You need to change your ResourceServlet mapping to

@WebServlet(name="ResourceServlet", urlPatterns={"/resources/*"})
于 2013-09-15T14:03:12.633 回答