Search code examples
javastruts

Issue with requests cancelled after resetting struts token


I have an issue in an older struts 1.3 application. There is a page which sets up a struts token using the saveToken() function. After a button is pressed a form is opened and in the back-end action, the token is reset to prevent multiple button presses. For yet unknown reasons multiple requests are being done against the backend .do endpoint (or one is cancelled and a new request made, little unclear what exactly is happening). The issue that arises is that the first request in most cases is allowed to run long enough so that resetToken() is run, invalidating the token, so that the next request being shot off is tripping isTokenValid() to be false, so the form never opens.

Is there a way for struts to catch if a request is being cancelled so that a new token can be setup?

Chrome developer is where I can see multiple requests are being done enter image description here


Solution

  • The issue seem to be related to how different browsers handle buttons without a specified onclick event using jquery. Chrome and Safari seem to want to be "helpful" by making a submit request to whatever matches the context, Firefox and Explorer/Edge seem to ignore it. The way, I fixed this issue, was by explicitly disabling the onclick event by adding this to the input tag:

    onclick="return false;"
    

    This seem to make the page only submit the struts action request and the issue of dueling requests went away.