Resolve JSP Form Duplicate submit problem __js

Source: Internet
Author: User
Tags session id

Method One: Using the synchronization token (Token) mechanism to solve the problem of repeated submissions in Web applications

This approach can only be a solution to the problem, but it is not possible to do so in a large project, which cannot solve the problem at all, and can be advanced to the background by rewriting the URL to skip the JS checksum.
A token mechanism is used in general projects to deal with this problem (for example, struts)

The token (token) mechanism of struts is a good solution to the problem of recurring forms, and the rationale is that the server side will compare the token value contained in the request to the token value saved in the current user session to see if the match is made before the incoming request is processed. After the request is processed, and before the reply is sent to the client, a new token is generated, which, in addition to being passed to the client, replaces the old token saved in the user's session. In this way, if the user returns to the previous submission page and submits the message again, the token from the client is inconsistent with the server-side token, thereby effectively preventing the recurrence of the commit.

This is actually two points, first: you need to have this token value in the request, how to save the token in the request, in fact, and we usually save some information in the page is the same, through the hidden fields to save, save the form such as: 〈input type= "hidden" name= " Org.apache.struts.taglib.html.TOKEN "value=" 6aa35341f25184fd996c4c918255c3ae ", This value is obtained by the Generatetoken () in the Tokenprocessor class, based on the current user's session ID and the long value of the current time. Second: After the client commits, we want to determine whether the value contained in the request is consistent with the server's token, because the server generates a new Token each time it commits, so if it is a duplicate commit, the client's Token value and the server-side Token value will be inconsistent. The next step is to insert a piece of data into the database to illustrate how to prevent duplicate submissions.

Struts1 a bit of trouble, so no use cases are provided.
Struts2 do well, as long as the <s:form></s:form> plus <s:token/> can automatically complete the duplicate submission (principle above

Method Two: JS

Http://www.ibeifeng.com/bbs/read-htm-tid-13978.html

I offer a simple solution with JavaScript
Write a hidden field in the form <input type= "hidden" value= "false" name= "resubmit"/>
If the first submission, change value= "true";
Once again, you can use JS in the client to determine Hidde value

var resubmit = false;
function Checkcfsubmit ()
{
if (resubmit)
{
return false;
}
Else
{
resubmit= true;
return true;
}

Then add the onsubmit= "Javascript:return checkcfsubmit () in the <form>";

Question 1

Basic application of CSS style sheet

Question 2

The use of dojo, the implementation of dynamic effects, the introduction of JAR packages

Question 3

Show the time of the JS component, download the use

Question 4 and how does the menu implement level display, is it an HTML tag, or is it a form (ordered form, unordered form)

Question 5 HTML5

Question 6 XML

Question 7 Spring's thinking

Issue 8 Hibernate transaction control

Problem 9 access Rights control implementation, develop a small module, test.

Question 10 Install Oracle Find My message board item, realize BBS pagination, nickname, Avatar, search by keyword ... (Search engine has no existing open source components to use directly, according to the user name search user's message, manage their own messages, reply function ....) )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.