简体   繁体   English

从浏览缓存加载页面时如何执行javascript?

[英]how to execute javascript when page is loaded from browse cache?

In my spring project i have solved the backbutton issue using the below interceptor. 在我的春季项目中,我使用以下拦截器解决了后退按钮的问题。

public class SampleInterceptor implements HandlerInterceptor
{
    public SampleInterceptor() {

    }

    @Override
    public void afterCompletion(HttpServletRequest arg0,
            HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {


    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
            Object object, ModelAndView model) throws Exception {


        if(request.getMethod().equals("GET"))
        {
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            response.setDateHeader("Expires", 0);
        }
        else if(request.getMethod().equals("POST"))
        {
            System.out.println("After post request : ");
        }

    }

}

I have cleared the browser cache for all request except post.Now user logged out and click back it does not go to the application only for get request.but post request it goes to the application.how to i avoid that problem in post request.If i cleared the browser cache for post request it asks confirm form submission.how to solve this issue? 我已经清除了除post之外的所有请求的浏览器缓存。现在用户已注销并单击返回,它不会仅针对get request进入应用程序。而是post request它将进入应用程序。如何避免post request中的问题。如果我清除了浏览器缓存以进行发布请求,它将要求确认表单提交。如何解决此问题? Any help will be greatly appreciated!! 任何帮助将不胜感激!!

It can be avoid by using AJAX instead of form submission. 通过使用AJAX而不是表单提交可以避免这种情况。 use AJAX POST to submit your request. 使用AJAX POST提交您的请求。

Also please refer below urls for more details: 1. Prevent Back button from showing POST confirmation alert 另请参阅以下网址以获取更多详细信息:1. 防止“后退”按钮显示POST确认警报

  1. http://en.wikipedia.org/wiki/Post/Redirect/Get http://en.wikipedia.org/wiki/Post/Redirect/Get

Thanks!!! 谢谢!!!

Post will always ask for form submission. 邮政将始终要求提交表单。

Either post your data using AJAX post and then redirect on receipt on response or submit your data constructing a get request. 您可以使用AJAX发布来发布您的数据,然后在收到回复后重定向,或者提交构成获取请求的数据。

Be aware than when a person does back on pages that update or insert data. 请注意,当有人回到更新或插入数据的页面时。 The data is re-posted to server and could lead to duplicate insert / updates. 数据将重新发布到服务器,并可能导致重复的插入/更新。 Do handle such cases if you intend to. 如果您愿意,请处理此类情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Wildfly 23 中浏览 Infinispan 缓存数据 - How to browse Infinispan cache data in Wildfly 23 如何在调用servlet /页面加载后立即执行方法/事件 - How to execute a method/event as soon as a servlet is called/page is loaded javascript已调用但未在页面上加载 - javascript called but not loaded on page 如何在Aem的下一页/上一页导航/浏览? - How to navigate/browse on next/previous page in aem? 如何过滤endeca(ATG)记录(/浏览页) - How to filter endeca (ATG) records (/browse page) 使用来自加载的网页的JavaScript调用重新加载WebView - Reloading a WebView with a JavaScript call from a loaded web page 如何从服务器上的Java类在浏览器的HTML页面中执行Javascript函数? - How to execute a Javascript function in an HTML page, in a browser, from a Java class on my server? 当包含在gwt.xml中时如何跳过加载外部JavaScript库? - How skip loading external JavaScript library from being loaded when included in gwt.xml? 如何获取完全加载页面的HTML(使用JavaScript)作为Java中的输入? - How to get html of fully loaded page (with javascript) as input in java? 当webview页面不同时,如何从java调用javascript函数 - How to call javascript function from java when webview page is different
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM