Ravee
Ravee

Reputation: 41

Struts action called twice -

When I submit a form to the browser,the form is submitted twice.The access log shows there are two requests arise at the same time.Two different threads executing it.

The thing is,the first request contains the attribute values that the user entered while the second request call contains only null values in request object.

Not all the times this issue occur.It happens only sometimes and not reproducible at all.Both in IE8 and IE9,I got these issues.

Do anyone know why does it happen?

Upvotes: 3

Views: 4612

Answers (2)

manish
manish

Reputation: 51

Maybe the problem is that you are using submit button and document.forms[0].submit within the javascript onclick event handler .

Thus action is called twice:

First time by

document.forms[0].submit

Second time by

submit button action

Upvotes: 5

user1431390
user1431390

Reputation:

Do you use struts1 or struts2? Anyway, they both have a mechanism to avoid repeat submit: token. For struts1, you need call saveToken() in the first action (the action for form page), and 'html:form' tag of struts will automatically add this token to your page; in your submit action (the action which dealing form), invoke isTokenValid(request, true), and this will validate the token from your page & your session.

For struts2, add the interceptor ref token for your submit action, and add 's:token' tag in your form page.

The above solutions restrict repeat submitting in server side, that the second request will cause a exception and handled as invalid request. But if you wanna restrict this in UI side, you need some javascript, like: when you click the submit button, disable it to avoid repeat submitting.

Upvotes: 1

Related Questions