Spring Tomcat and static resources and mvc:resources

后端 未结 3 1636
一向
一向 2020-12-10 05:59

I started doing a web app from scratch. Before I\'ve always been working on apps that were already running for a long time, so I didn\'t have to deal with the full setup pha

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 06:12

    I had the same problem, too. I solved it by adding the spring macro before the actual reference to the resource, in order to resolve the servlet path.

    It is not really nice in the code, but this solution makes you being independent from the actual context under which your application is deployed on the server and your servlet too. Usually, you don't want to have the actual servlet being mentioned in your url.

    For instance, refering to the answer of ColdStoneJava, that would be:

      
    

    You also have to reference it absolute in the url, so the slash '/...' is essential.

    This, won't work in my experience:

      
    

    Cheers.

提交回复
热议问题