How to access static resources when mapping a global front controller servlet on /*

前端 未结 19 2127
轮回少年
轮回少年 2020-11-22 07:35

I\'ve mapped the Spring MVC dispatcher as a global front controller servlet on /*.

               


        
19条回答
  •  北海茫月
    2020-11-22 08:15

    In section "12.2 Specification of Mappings" of the Servlet Specification, it says:

    A string containing only the ’/’ character indicates the "default" servlet of the application.

    So in theory, you could make your Servlet mapped to /* do:

    getServletContext().getNamedDispatcher("/").forward(req,res);
    

    ... if you didn't want to handle it yourself.

    However, in practice, it doesn't work.

    In both Tomcat and Jetty, the call to getServletContext().getNamedDispatcher('/') returns null if there is a servlet mapped to '/*'

提交回复
热议问题