如何使用Struts2禁用后退按钮 [英] How to Disable back button using Struts2

查看:116
本文介绍了如何使用Struts2禁用后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 struts.serve.static = true struts.serve.static.browserCache = false ,但退出按钮即使在注销后也能正常工作。当我点击后退按钮时,它将转到上一个屏幕。我如何解决这个问题?

I am using struts.serve.static=true and struts.serve.static.browserCache=false, but the back button is working even after logout. When i click on the back button it is going to the previous screen. How do i solve this issue?

推荐答案

S2将使用上述常量告诉浏览器是否需要缓存静态内容。

The above constants will be used by S2 to tell browser if they need to cache static content.

struts.serve.static=true

以上属性由使用FilterDispatcher


  • 如果为true,则Struts从其jar中提供静态内容。

  • 如果为false,则静态内容必须位于/ struts

struts.serve.static.browserCache = true FilterDispatcher 使用,仅当 struts.serve时才有效.static = true


  • 如果为true - > Struts将为静态内容写出标题,这样他们就会
    由网络浏览器缓存(使用Date,Cache-Content,Pragma,Expires)
    header)。

  • 如果为false - > Struts将为静态写出标头内容使得它们是
    不被网络浏览器缓存(使用Cache-Content,Pragma,Expires
    标题)
    简而言之这两个常量都是一种告诉浏览器是否需要的方法缓存静态内容是否由S2提供。

关于浏览器后退按钮,我们无法禁用浏览器后退按钮作为浏览器的一部分API以及当您按下后退按钮时,浏览器正在为c提供服务来自其缓存的ontent而不是命中服务器。

Regarding browser back button we can not disable browser back button as its a part of Browser API and when you are hitting the back button browser is serving the content from its cache without hitting the server.

您可以要求浏览器不使用缓存控制标头来缓存内容,但是在浏览器上是否尊重它们。在JSP中使用以下代码

You can ask the browser not to cache the content by using cache control header but its upon the browser to respect them or not. use following code in your JSP

response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires", "0");

或者,您可以创建一个拦截器并使用所需的操作对其进行配置,以便可以设置标头。
请通过以下主题了解如何在S2中控制缓存的更多细节

Alternatively you can create an Interceptor and configure it with your desired action so that the headers can be set. Please go through the following thread for more details as how to control the cache in S2

  • Handling-Browser-Back-Forward-Button-in-Struts2

这篇关于如何使用Struts2禁用后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆