`

chrome下面的GET问题

阅读更多

问题描述:在chrome(IE无此问题)下面用GET提交数据,会重复提交两次!(自己在网上找了个spring mvc 下TOKEN的防止重复提交,还是不行,这个方法有问题)。可以看截图,前三个为一组,后两个为一组,都能发现,不管是GET提交,还是POST提交,都会多一个GET提交出来,且他的REFERER为该请求,这太不科学了。

 

 

解决办法:将所有请求都是POST提交,且后台mapping 为method=RequestMethod.POST 。这样第二次的冗余GET请求就会找不到方法,从而无法提交,但是这个冗余的请求还是发出去了,只是无法进入后台,因为前台是GET,后台是POST

 

 

再附一个题外话:防止重复提交的4种方法。PS:spring mvc 封装的没有struts2好啊,token,数据bind 都没有struts2好。

http://technoesis.net/prevent-double-form-submission/

 

Double form submission in a multi-user web based application the most common and critical issue as well. There are many scenarios where we face duplicate submission problem like,

  • Clicking submit button twice.
  • Using Refresh button.
  • Using browser back button traverse back and re-submitting the form.
  • Using browser history feature and re-submit the form.
  • Duplicate HTTP requests from browser.

 

There are several ways to Prevent double form submission

Disable the Submit Button. Use JavaScript to disable the button a few ms after click. This will avoid multiple submits being caused by impatient users clicking multiple times on the button.  A weakness of this is if clients have JavaScript disabled.

My previous post shows a nice way to prevent double form submission using a jQuery plugin.

The Post / Redirect / Get pattern. Send a redirect after submit, this is known as Post-Redirect-Get (PRG) pattern. In short, when the user posts the form, you perform a client side redirect (after consuming the post data) to the response (success) page.

This will avoid multiple submits being caused by users pressing F5 on the result page and ignoring the browser warning that the data will be resend, or navigating back and forth by browser back/forward buttons and ignoring the same warning.

Store a Unique Token in the session. Generate an unique token when the page is requested and put in both the session scope and as hidden field of the form. During processing, check if the token is there and then remove it immediately from the session and continue processing.

If you get a form submission without a valid token, it means that the form has already been submitted and ignore it.

This has the added advantage of adding XSRF protection to your project.

Add Constraint in Database. Change the database to not allow duplicates by adding an unique constraints or creating a unique index. A unique index is an index that requires that each value of the indexed field is unique. This is the most effective solution for preventing double request’s impact.

 

  • 大小: 89 KB
  • 大小: 220.9 KB
  • 大小: 225.5 KB
  • 大小: 278.6 KB
  • 大小: 274.6 KB
分享到:
评论

相关推荐

    python:selenium测试登录在chrome中闪退.doc

    Python 中 Selenium 测试登录 Chrome 闪退问题解决方案 在使用 Python 的 Selenium 库时,可能会出现 Chrome 浏览器闪退的问题,本文将对该问题进行详细的分析和解决方案。 问题描述 使用 Selenium.webdriver 时...

    chromerest控制GoogleChrome的RESTAPI

    下面,我们将深入探讨Chrome REST的相关知识点。 一、Chrome REST API介绍 Chrome REST API是基于Python开发的,它提供了一种简单的方式来与Google Chrome进行交互,通过HTTP请求执行各种操作,如打开新标签页、...

    windows server 2008上可以使用的chrome和chromedriver

    下面将详细介绍Windows Server 2008上安装Chrome和ChromeDriver的步骤,以及如何使用它们进行自动化测试。 首先,我们需要下载适用于Windows Server 2008的Google Chrome浏览器安装包。Chrome浏览器通常会根据系统...

    Chrome无头模式–headless1

    下面我们将详细介绍 Chrome 无头模式的使用方法和相关知识点。 一、 Chrome 无头模式的使用 Chrome 无头模式可以使用 selenium 库来实现。首先,需要引入 selenium 库和 chrome 选项,然后添加无头模式参数,最后...

    Delphi Chrome.7z

    下面我们将详细探讨 Delphi Chrome 的关键知识点。 一、Delphi 环境介绍 Delphi 是一款强大的面向对象的 Pascal 编程环境,由 Embarcadero Technologies 公司开发和维护。它以其高效的编译器和直观的集成开发环境...

    常用的Chrome插件

    5. **隐私与安全考虑**:尽管Chrome插件带来了便利,但也需要注意隐私和安全问题。某些插件可能会收集用户数据,或者成为恶意软件的入口。因此,只应从官方商店下载插件,并定期更新以获取最新的安全补丁。 综上所...

    chrome-postman插件

    下面将详细介绍Postman的功能、使用方法以及它如何帮助我们在日常开发工作中提高效率。 首先,Postman作为一款Chrome扩展程序,安装非常便捷。在Chrome应用商店中搜索"Postman",找到官方插件并添加至浏览器即可。...

    chrome 版本66 64位 和chromedriver_64 mac安装包

    Chrome浏览器是Google开发的一款流行的、开源的网络浏览器,其64位版本在处理大量内存和高性能计算时表现出色。...记住,始终确保ChromeDriver与你的Chrome浏览器版本相匹配,否则可能会遇到兼容性问题。

    chrome67.0的Chromedriver

    在上述代码中,`webdriver.Chrome()`函数会启动一个新的Chrome浏览器实例,并通过`get()`方法导航到指定的URL。`find_element_by_id()`用于定位页面上的元素,`click()`则模拟点击操作。最后,`quit()`方法关闭...

    selenium打开指定Chrome账号.doc

    至此,通过上述步骤,可以成功地使用 Selenium 打开指定的 Chrome 用户账号,并避免了多开 Chrome 时可能遇到的问题。 ### 总结 本文详细介绍了如何使用 Selenium 打开指定的 Chrome 账号,包括获取必要的配置信息...

    chrome扩展 postman

    下面将详细介绍Postman的使用及相关知识点。 1. 安装与启用: - 首先,你需要下载Postman的离线安装包,如这里提供的`postman-4.1.2`。 - 在Chrome浏览器中,进入设置页面,选择“更多工具”> “扩展程序”。 - ...

    python+selenium+chrome设置geo经纬度地理位置并自动发布抖音视频

    下面将详细介绍如何通过Python结合Selenium和Chrome浏览器设置地理定位(即经纬度)来自动发布抖音视频。 首先,`selenium`是一个强大的Web自动化测试框架,它可以模拟真实用户的浏览器操作,如点击、滚动、填写...

    PySe自动化chrome安装软件.zip

    下面是一个简单的示例: ```python from selenium import webdriver # 创建Chrome浏览器对象,指定chromedriver的位置 driver = webdriver.Chrome(executable_path='path/to/chromedriver') # 打开一个网页 ...

    Chrome抢票小插件demo

    此外,jQuery还能帮助开发者处理跨浏览器兼容性问题,使得代码在不同版本的Chrome上都能正常运行。 `ab_linkman.png`可能是插件的图标,显示在Chrome浏览器的右上角,用户可以通过点击这个图标来启用或禁用插件。在...

    简易后台服务post/get

    下面将详细阐述相关知识点。 1. **Node.js**:Node.js是基于Chrome V8引擎的JavaScript运行环境,它通过提供异步I/O模型和事件驱动的API,使得开发高性能网络应用变得更加高效。Node.js特别适合构建实时、可伸缩的...

    linux 谷歌浏览器开机自启并全屏

    下面是安装Python 3.6.5的详细过程: 1. 更新系统包: ```bash sudo yum update -y ``` 2. 安装必要的库和依赖: ```bash sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-...

    chrome postman浏览器插件

    Chrome上的Postman是一款非常强大的API开发、测试和文档管理工具,尤其在Web服务接口的调试和集成测试方面表现卓越。Postman不仅是一个浏览器插件,更是一个独立的应用程序,支持多平台,包括Windows、Mac和Linux。...

    Postman for chrome-V5.4.0_0汉化版

    下面将详细阐述Postman的主要特点、功能及其在API测试中的应用。 首先,Postman的界面简洁直观,无论是初学者还是经验丰富的开发者,都能快速上手。它的汉化版本使得中文用户能够无障碍地理解和操作各项功能,极大...

    Vue resource中的GET与POST请求的实例代码

    下面将详细介绍 Vue Resource 中的 GET 与 POST 请求实例代码,以及相关的使用方法和参数说明。 GET 请求 在 Vue Resource 中,GET 请求可以使用 `Vue.http.get()` 方法来实现。该方法接受三个参数:url、params ...

    selenium设置proxy、headers的方法(phantomjs、Chrome、Firefox)

    下面详细介绍如何使用Selenium设置代理和请求头,适用于PhantomJS、Chrome和Firefox三种浏览器。 #### PhantomJS 设置 Proxy 和 Headers **设置 Proxy** 在PhantomJS中设置代理有两种主要方式: 1. **使用 `...

Global site tag (gtag.js) - Google Analytics