2015-12-23 91 views
3

304未修改響應如果資源(的index.html)在客戶端已經緩存,例如響應頭:使用防止在Tomcat中

"Cache-Control": "max-age=0, must-revalidate, proxy-revalidate" 

如何防止Tomcat能夠與在一個304 Not Modified響應下一個請求服務器?無論如何,我想強制服務器以200而不是304響應。 我試圖設置

httpResp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, proxy-revalidate"); 
httpResp.setHeader("Pragma", "no-cache"); 
httpResp.setHeader("Expires", "0"); 

但它只適用於第二個請求。第一個請求仍然得到304. 我試圖覆蓋if-modified-since標題使用HttpServletRequestWrapper與過去的值,如Mon, 06 Dec 2010 01:34:46 GMT沒有運氣 - 客戶端仍然獲得304響應,雖然該文件已於2015年修改。 有什麼辦法可以防止304迴應?也許通過tomcat配置?

回答

0

不知道這是否會幫助,但你可以嘗試以下方法 -

  1. 刪除瀏覽器緩存從頭開始,並測試它是否管用不

  2. 從另一個ServerFault改編問題 -

https://serverfault.com/questions/40205/how-do-i-disable-tomcat-caching-im-having-weird-static-file-problems?answertab=votes#tab-top

更改cachingAllowed標誌後,可能必須在/ work/Catalina/localhost中刪除應用程序緩存文件夾。 配置可以在server.xml中引入,因爲

<Context className="org.apache.catalina.core.StandardContext" 
      cachingAllowed="false" 
      charsetMapperClass="org.apache.catalina.util.CharsetMapper" 
      cookies="true" 
      reloadable="false" 
      wrapperClass="org.apache.catalina.core.StandardWrapper"> 
    </Context>