我正在使用Tuckey URLRewriteFilter。在我的應用程序,我有以下的頁面和按鈕:URL重寫篩選器的異常行爲
- 頁
inside.xhtml
這是應用程序的上下文中:http://example.com/app/inside.xhtml - 頁
outside.xhtml
這是應用程序的範圍之外:http://example.com/outside.xhtml - 頁
login.xhtml
在http://example.com/app/login.xhtml - A
login button
在outside.xhtml
頁面去login.xhtml
頁面。 - 頁
profile.xhtml
在http://example.com/app/profile.xhtml - 一個
logout button
上profile.xhtml
頁去inside.xhtml
頁面。
在umlrewrite.xhtml
文件,我有以下規則來重定向從inside.xhtml
到outside.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
頁。我期望發生的是以下流程:
- 衝到
outside.xhtml
。 - 點擊
login button
轉到login.xhtml
並登錄。 - 成功登錄後到達
profile.xhtml
。 - 點擊
logout button
去inside.xhtml
。 - 重定向到
outside.xhtml
。
然而,實際發生的事情是:
- 衝浪
outside.xhtml
。 - 點擊
login button
去login.xhtml
並登錄。 - 突然得到重定向回
outside.xhtml
。 - 點擊
login button
去login.xhtml
並重新登錄(應用程序沒有記錄我的登錄)。 - 成功登錄時到達
profile.xhtml
。 - 點擊
logout button
去inside.xhtml
。 - 重定向到
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);
}
我已經更新了我的答案。那是你需要的嗎?有一點需要注意的是,如果沒有這個「規則」,一切正常。我想我應該已經正確記錄了「登錄」狀態。 – 2013-03-11 18:53:40
您的更新表明您依賴於容器的會話處理。我最好的猜測是你的容器將會話cookie設置爲當前路徑(「/ app」)。當您重定向到父級時,會話會丟失,直到您再次登錄。這只是一個猜測。根據我的回答,您確實需要在HTTP請求中查看cookie標頭。如果更容易,您也可以嘗試在流程中的各個階段記錄會話ID。我的猜測是,即使你不期望它會改變。 – kaliatech 2013-03-11 19:04:07