How to handle static content in Spring MVC?

前端 未结 23 2474
春和景丽
春和景丽 2020-11-22 03:28

I am developing a webapp using Spring MVC 3 and have the DispatcherServlet catching all requests to \'/\' like so (web.xml):

  
          


        
23条回答
  •  渐次进展
    2020-11-22 03:52

    I found a way around it using tuckey's urlrewritefilter. Please feel free to give a better answer if you have one!

    In web.xml:

    
        UrlRewriteFilter
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
    
    
    
        UrlRewriteFilter
        /*
    
    
      
        app
        org.springframework.web.servlet.DispatcherServlet
      
    
      
        app
        /app/*
      
    

    In urlrewrite.xml:

    
    
        /
        /app/
    
    
        ^([^\.]+)$
        /app/$1
    
    
        /app/**
        /$1
        
    

    This means that any uri with a '.' in it (like style.css for example) won't be re-written.

提交回复
热议问题