2017-10-14 133 views
2

我們有一個JSF應用程序中運行。自從默認着陸頁被定義爲/pages/dashboard.xhtml以來。JSF默認頁(解決:謹防瀏覽器的301-緩存)

四郎正在迎頭趕上的要求,顯示了登錄頁面,和全成身份驗證後,我們的servlet檢索來自四郎所存儲的請求並轉發該用戶到該頁面。

所以,每次其他種類的深層鏈接是可能的OFC。


現在,我們希望允許用戶定義他的默認登錄頁面。系統設置,如果四郎不提供存儲的請求,我們的應用程序轉發到用戶定義自己的着陸頁。

(其他深層鏈接仍然工作OFC)

如果現在用戶直接調用https://example.com/app/login.xhtml,他被轉發到他的習慣着陸頁。 (登錄後)

這是奇怪的唯一的事 - 和我逼瘋了,現在如果用戶僅請求https://example.com/app - 第一個請求hiting四郎是鏈接到舊儀表盤再次:https://example.com/app/pages/dashboard.xhtml


在web.xml中,我們繪製了servlet來*.xhtml

<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern> 
    </servlet-mapping> 

和定義的歡迎文件列表作爲

<welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    </welcome-file-list> 

該文件存在,並且只包含

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta http-equiv="Refresh" content="0; URL=login.xhtml"> 
</head> 
</html> 

好像該文件是永遠不會被調用。當移除重新導向,呼籲立即https://example.com/app導致https://example.com/app/login.xhtml - 但四郎記錄的訪問請求https://example.com/app/pages/dashboard.xhtml,導致了「存儲的請求」,然後。

(我們不喜歡,會導致SZENARIO應該在用戶的默認着陸頁)

這是wildfly 8.1,我完全出在哪裏這個「請求」被觸發的想法。 (顯然,這是不是默認頁) - 但它擊中我們的網址重寫過濾器的第一個請求,所以調用應用程序之前,musst發生......

但在哪裏呢?

回答

1

尷尬......

<meta http-equiv="Refresh" content="0; URL=login.xhtml"> 

被認爲是301(永久移動)和鉻是緩存即使DEV-工具(禁用緩存)此重定向是開放的。只有手動清除緩存才能解決此問題。

因此,Chrome絕不會調用(新)index.xhtml,在它之前是<meta http-equiv="Refresh" content="0; URL=/pages/dashboard.xhtml">

因此,對於時間的緩存可能還活着的任何客戶端上的唯一的選擇似乎是變化的原因:考慮存儲的請求舊儀表盤爲沒有存儲的請求 ...

更新:它看起來像瀏覽器可能會緩存301S的時間無限量: How long do browsers cache HTTP 301s?

意思是:現在我需要忽略這個存儲的請求。如果用戶將其設置爲自定義登錄頁面,則會稍後處理。

 FacesContext context = FacesContext.getCurrentInstance(); 
     ServletRequest request = (ServletRequest) context.getExternalContext().getRequest(); 
     SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request); 

     if ((savedRequest != null) && (savedRequest.getRequestUrl() != null)) { 
      /** 
      * Browser might cache the 301 redirect from index.xhtml 
      * for an infinite amount of time. So, as of now, we can only consider 
      * the old "dashboard" to be an "unstored request". 
      * 
      */ 
      if (!savedRequest.getRequestUrl().contains("/pages/dashboard.xhtml")) { 
       return savedRequest.getRequestUrl(); 
      } 
     } 

     // No stored request. Get Custom Landingpage. 
     String defaultLandingPage = this.userValueService.getValue(UserValueKey.defaultLandingPage); 
     return ProjectStageConfiguration.getInstance().getWebContextPath() + defaultLandingPage;