URL重写过滤器的异常行为

时间:2013-03-11 16:26:48

标签: java jsf-2 url-rewriting tuckey-urlrewrite-filter

我正在使用Tuckey URLRewriteFilter。在我的应用程序中,我有以下页面和按钮:

  1. 页面inside.xhtml位于应用内容中:http://example.com/app/inside.xhtml
  2. 页面outside.xhtml不在应用的上下文中:http://example.com/outside.xhtml
  3. http://example.com/app/login.xhtml
  4. 页面login.xhtml
  5. login button页面上的outside.xhtml转到login.xhtml页面。
  6. http://example.com/app/profile.xhtml
  7. 页面profile.xhtml
  8. logout button页面上的profile.xhtml转到inside.xhtml页面。
  9. 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页面。我期望发生的是以下流程:

    1. 浏览outside.xhtml
    2. 点击login button转到login.xhtml并登录。
    3. 成功登录后到达profile.xhtml
    4. 点击logout button转到inside.xhtml
    5. 重定向到outside.xhtml
    6. 然而,实际发生的是:

      1. 浏览outside.xhtml
      2. 点击login button转到login.xhtml并登录。
      3. 突然重定向回outside.xhtml
      4. 点击login button转到login.xhtml并重新登录(该应用未记录我的登录信息)。
      5. 成功登录后到达profile.xhtml
      6. 点击logout button转到inside.xhtml
      7. 重定向到outside.xhtml
      8. 如果我在步骤2之后继续执行步骤7,则会反复发生上述情况。

        如果没有<rule>,我会在成功登录时正确地重定向到profile.xhtml页面。

        如果你能就这个问题给我一些建议,我将非常感激。

        更新

        在我的应用中,为了跟踪logged in状态,我有一个@SessionScoped托管bean,其中包含一个记录状态的简单方法:

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

1 个答案:

答案 0 :(得分:0)

您没有指定跟踪“登录”状态的方式。您使用的是自定义Cookie吗?依赖于应用服务器的内置会话处理(可能也基于cookie)?

问题的最可能原因与您跟踪登录状态的方式有关,以及您在各个页面之间如何传递状态&amp;上下文。 (特别是在从登录状态转换为profile.xhtml时。)请记住,cookie可以基于路径。

调试问题:

  • 如果您使用的是浏览器,请使用firebug / developer-tools并观看网络标签。特别要检查流程中每个步骤中设置的各种标题。

  • 如果没有使用浏览器,请尝试使用CharlesFiddler等代理。

我认为通过在流程中观察HTTP标头,潜在的问题将变得明显。