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

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

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

               


        
19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 08:18

    I'd recommend trying to use a Filter instead of a default servlet whenever possible.

    Other two possibilities:

    Write a FileServlet yourself. You'll find plenty examples, it should just open the file by URL and write its contents into output stream. Then, use it to serve static file request.

    Instantiate a FileServlet class used by Google App Engine and call service(request, response) on that FileServlet when you need to serve the static file at a given URL.

    You can map /res/* to YourFileServlet or whatever to exclude it from DispatcherServlets' handling, or call it directly from DispatcherServlet.

    And, I have to ask, what does Spring documentation say about this collision? I've never used it.

提交回复
热议问题