Tomcat serving static content

前端 未结 3 860
孤城傲影
孤城傲影 2020-12-19 14:02

I have a Spring app and I\'m wondering the best way to serve static content. I have tried the following:


    defa         


        
3条回答
  •  死守一世寂寞
    2020-12-19 14:24

    There are several better ways to serve static content.

    The traditional approach was to use a UrlRewriteFilter to remap URLs as follows:

    web.xml:

    
        UrlRewriteFilter
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
    
    
        UrlRewriteFilter
        /*
    
    ...
    
        Spring MVC Dispatcher Servlet
        /app/*
    
    

    urlrewrite.xml:

    
        
            /images/**
            /images/$1
        
        
            /scripts/**
            /scripts/$1
        
        
            /styles/**
            /styles/$1
        
        
            /**
            /app/$1
        
    
    

    This approach can be seen in the most of Spring samples.


    Spring 3.0.1 introduced a newer apporach - it can serve static content via DispatcherServlet. It can be configured using element in Spring's config file. In Spring 3.0.4 it was extended with support of multiple location and cache control options, see 15.12.4 mvc:resources.

提交回复
热议问题