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

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

问题描述

我正在使用 struts.serve.static=truestruts.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 时才有效.

also struts.serve.static.browserCache=true is used by FilterDispatcher and will work only if struts.serve.static=true.

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

关于浏览器后退按钮,我们不能将浏览器后退按钮作为浏览器 API 的一部分禁用,并且当您点击后退按钮时,浏览器会从其缓存中提供内容而无需访问服务器.

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

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

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