【问题标题】:JSF Default Page (Resolved: Beware of 301-Caches of Browsers)JSF 默认页面(已解决:小心浏览器的 301 缓存)
【发布时间】:2017-10-23 22:36:09
【问题描述】:

我们有一个 JSF 应用程序正在运行。自从默认登陆页面被定义为/pages/dashboard.xhtml

Shiro 正在捕获请求,显示登录页面,在成功验证后,我们的 servlet 从 shiro 检索存储的请求并将用户转发到该页面。

因此,其他所有类型的深层链接都是可能的。


现在,我们希望允许用户定义他的默认登录页面。系统设置完毕,如果 shiro 没有提供存储的请求,我们的应用程序会将用户转发到他定义的登录页面。

(其他深层链接仍在工作。)

如果用户现在直接拨打https://example.com/app/login.xhtml,他会被转到他的自定义登录页面。 (登录后)

唯一奇怪的是——现在让我发疯了:如果用户只请求https://example.com/app——第一个命中 shiro 的请求又是指向旧仪表板的链接: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 - 但shiro 将访问请求记录到https://example.com/app/pages/dashboard.xhtml,然后导致“存储请求”。

(我们不喜欢,因为 szenario 应该使用用户的默认登录页面)

这是wildfly 8.1,我完全不知道触发这个“请求”的地方。 (显然它不是默认页面)——但它是第一个访问我们的 url-rewrite 过滤器的请求,所以它必须在应用程序被调用之前发生......

但是在哪里?

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    尴尬...

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

    被认为是 301(永久移动),即使开发工具(禁用缓存)打开,chrome 也会缓存此重定向。只有手动清除缓存才能解决这个问题。

    因此,chrome 从未调用(新)index.xhtml,因为在更改之前它是 &lt;meta http-equiv="Refresh" content="0; URL=/pages/dashboard.xhtml"&gt;

    因此,对于任何客户端上的缓存可能处于活动状态的时间,唯一的选择似乎是:将对旧仪表板的存储请求视为没有存储请求。 ..

    更新:似乎浏览器可能会无限期地缓存 301: 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-05
      • 2014-05-26
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      相关资源
      最近更新 更多