2013-03-11 21 views
0

我正在使用Tuckey URLRewriteFilter。在我的應用程序,我有以下的頁面和按鈕:URL重寫篩選器的異常行爲

  1. inside.xhtml這是應用程序的上下文中:http://example.com/app/inside.xhtml
  2. outside.xhtml這是應用程序的範圍之外:http://example.com/outside.xhtml
  3. login.xhtmlhttp://example.com/app/login.xhtml
  4. A login buttonoutside.xhtml頁面去login.xhtml頁面。
  5. profile.xhtmlhttp://example.com/app/profile.xhtml
  6. 一個logout buttonprofile.xhtml頁去inside.xhtml頁面。

umlrewrite.xhtml文件,我有以下規則來重定向從inside.xhtmloutside.xhtml

<rule> 
    <note> 
     Requests to /app/inside.xhtml will be redirected to ./../../outside.html 
    </note> 
    <from>/app/inside.xhtml</from> 
    <to type="redirect">./../../outside.html</to> 
</rule> 

我的邏輯是,用戶在login.xhtml頁面登錄後,他將被重定向到profile.xhtml頁。我期望發生的是以下流程:

  1. 衝到outside.xhtml
  2. 點擊login button轉到login.xhtml並登錄。
  3. 成功登錄後到達profile.xhtml
  4. 點擊logout buttoninside.xhtml
  5. 重定向到outside.xhtml

然而,實際發生的事情是:

  1. 衝浪outside.xhtml
  2. 點擊login buttonlogin.xhtml並登錄。
  3. 突然得到重定向回outside.xhtml
  4. 點擊login buttonlogin.xhtml並重新登錄(應用程序沒有記錄我的登錄)。
  5. 成功登錄時到達profile.xhtml
  6. 點擊logout buttoninside.xhtml
  7. 重定向到outside.xhtml

如果我在步驟7後繼續執行步驟2,上述情況會重複發生。

沒有這個<rule>,我總是被重定向到profile.xhtml成功登錄頁面正確。

如果你能給我一些關於這個問題的建議,我將不勝感激。

UPDATE:

在我的應用程序,跟蹤logged in狀態,我有一個包含一個簡單的方法來記錄狀態@SessionScoped託管bean:

public void recordUserLoggedIn(HttpServletRequest request) { 
    HttpSession clientSession = request.getSession(); 
    clientSession.setAttribute("isLogin", true); 
} 

回答

0

不指定如何正在跟蹤「登錄」狀態。您是否使用自定義Cookie?依靠應用程序服務器的內置會話處理(這可能也是基於cookie的)?

問題的最可能原因與您如何跟蹤登錄狀態有關,以及您的各種頁面之間的狀態是如何傳遞的。 (尤其是從登錄過渡到profile.xhtml時)。請記住,Cookie可以是基於路徑的。

要調試您的問題:

  • 如果您使用的瀏覽器,然後用firebug/developer-tools和收看網絡選項卡。尤其是查看流程中每個步驟所設置的各種標題。

  • 如果不使用瀏覽器,請嘗試使用代理,如CharlesFiddler

我認爲你的流動過程看HTTP頭,潛在的問題就會變得很明顯。

+0

我已經更新了我的答案。那是你需要的嗎?有一點需要注意的是,如果沒有這個「規則」,一切正常。我想我應該已經正確記錄了「登錄」狀態。 – 2013-03-11 18:53:40

+0

您的更新表明您依賴於容器的會話處理。我最好的猜測是你的容器將會話cookie設置爲當前路徑(「/ app」)。當您重定向到父級時,會話會丟失,直到您再次登錄。這只是一個猜測。根據我的回答,您確實需要在HTTP請求中查看cookie標頭。如果更容易,您也可以嘗試在流程中的各個階段記錄會話ID。我的猜測是,即使你不期望它會改變。 – kaliatech 2013-03-11 19:04:07