2010-11-08 46 views

回答

23

嘗試(與改變的值)

<mvc:resources mapping="/static/**" location="/public-resources/" 
     cache-period="31556926"/> 
<mvc:annotation-driven/> 

您也可以使用攔截器:

<mvc:interceptors> 
    <mvc:interceptor> 
    <mvc:mapping path="/static/*"/> 
    <bean id="webContentInterceptor" 
     class="org.springframework.web.servlet.mvc.WebContentInterceptor"> 
     <property name="cacheSeconds" value="31556926"/> 
     <property name="useExpiresHeader" value="true"/> 
     <property name="useCacheControlHeader" value="true"/> 
     <property name="useCacheControlNoStore" value="true"/> 
    </bean> 
    </mvc:interceptor> 
</mvc:interceptors> 

MVC docs

+1

一個微小的更正,正確的標記是「mvc:mapping」而不是「映射」,即正確的完整標記是: 2013-03-26 17:14:51

+0

我應該使用哪一個?目前處於兩種情況,並且都想知道是否需要這兩種情況,似乎我應該選擇其中一種。使用mvc:resources元素有什麼好處嗎? – 2014-01-07 14:23:57

+1

在'304'的情況下,客戶端也會發送一個HTTP請求服務器,然後它是如何受益 – manish 2014-12-02 17:32:23

1

如果使用Spring 3.0,則<mvc:resources>是實現靜態資源緩存的一種方法。 This link有一些文檔。

相關問題