【问题标题】:How to properly logout from GWT app to avoid browser loading cached data?如何正确退出 GWT 应用程序以避免浏览器加载缓存数据?
【发布时间】:2014-07-12 06:05:25
【问题描述】:

我有一个基于 GWT 构建的企业 Web 应用程序,可以通过外部身份验证模块进行访问。我的问题是:

  • 我使用登录页面登录应用程序。
  • 我被定向(使用反向代理规则)到我加载 GWT 应用程序的 Tomcat 服务器。
  • 使用该应用程序。
  • 我退出了应用程序。
  • 当我尝试重新登录时,我没有进入登录页面。

如果我再次输入登录页面的 URL,浏览器会开始加载我无法访问登录页面的缓存数据。我必须点击重新加载才能进入登录页面。怎么会这样? F5 告诉浏览器不要使用缓存有什么特别之处?

我知道代理不会被我的任何请求击中,这意味着浏览器所做的只是加载缓存的元素。

有人有线索吗?

【问题讨论】:

  • 必须与 HTTP 缓存语义有关。如果内容不可缓存,请确保发送适当的 HTTP 标头。
  • 刚刚注意到,如果我登录然后我关闭反向代理,然后在我已经登录的页面上键入 URL,我得到浏览器正在从缓存加载的行为,但是挂起。
  • 我相信我需要将一个关键的 GWT 元素标记为“不可缓存”,比如 HTML 入口页面。
  • 任何受密码保护的资产都应该是不可缓存的。您可以通过 HTTP 身份验证免费获得它,但在使用 cookie 时必须强制执行它。

标签: javascript gwt


【解决方案1】:

我没有清楚地理解你的问题,但我想我有一个类似的问题。我希望它对你有帮助。

我的 GwtPage.html 和所有 GWT 内容都保存在 web.xml 中。

当我第一次访问http://example.com/GwtPage.html 时,容器的安全性将我发送到 login.jsp。登录完成后,我被发送到 GwtPage.html,所以一切都很好。

但是 GwtPage.html 第二次被浏览器缓存并且容器没有向我发送 login.jsp。所以我做了以下事情: 我只用一行创建了 index.jsp:

<%
    response.sendRedirect("GwtPage.html");
%>

并将其添加到受保护的资源列表中。

浏览器不会缓存它,因此容器总是向我发送登录页面。

第二个好处是 GwtPage.html 仍然被浏览器缓存,这是非常好的,因为它很重。

我的 web.xml:

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

<!-- Security -->
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Index Page</web-resource-name>
        <url-pattern>/index.jsp</url-pattern>
    </web-resource-collection>    
    <web-resource-collection>
        <web-resource-name>Main Page</web-resource-name>
        <url-pattern>/GwtPage.html</url-pattern>
    </web-resource-collection>
    <web-resource-collection>
        <web-resource-name>Gwt entrails</web-resource-name>
        <url-pattern>/Gwt/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>VIEWER</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>myrealm</realm-name>
    <form-login-config>
        <form-login-page>/LoginForm.jsp</form-login-page>
        <form-error-page>/LoginError.jsp</form-error-page>
    </form-login-config>
</login-config>

【讨论】:

  • 我一定会试一试的。
【解决方案2】:

我遇到了同样的问题。 注销后 GWT 模块未启动。

<a id="logout" href="${pageContext.request.contextPath}/j_spring_security_logout">Logout</a>

解决方法很简单,打开登录页面前应该自动刷新

在 spring-security.xml

&lt;security:logout logout-success-url="/logout.html"/&gt;

logout.html

<head lang="en">
  <meta http-equiv="REFRESH" content="0;  url=login.html">
</head>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 2012-01-10
    • 2014-04-01
    • 1970-01-01
    • 2011-03-25
    相关资源
    最近更新 更多