2

Here's scenario(sorry but this is going to be theoretical question).

I am developing a e-commerce web application struts2 which in normal case handles 5000-6000 users, but there are few occasions when number of users may go above 600k.

I have a web form consisting of more than 25 fields I have few upload fields for images and documents, when the server is heavy on load form takes more than 5 minutes to get a response.

So here's an issue I am facing while the request is getting processed consider few users are impatient and may click submit button again and again in such case I am unnecessarily increasing the load. I want to block all other duplicate requests.

So How should I tackle this situation?

I have heard of interceptors token and tokenSession

<interceptor-ref name="token"></interceptor-ref>
<interceptor-ref name="tokenSession"></interceptor-ref>

But I guess these interceptors only handles refresh and Back button based duplicate form submission issue. in fact, I have tried the implementation mentioned in below link.

http://www.journaldev.com/2281/struts2-token-interceptor-to-handle-double-form-submission-problem

[Edit] :
The forms after user login, should have a token value which should change for every refresh of the page and it should be validated at server side whether its server generated valid token for that specific user or not or proper captcha implementation should be there. This is to avoid, our form submission from external websites. Hope you understood.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
  • What about the implementation in the link you posted didn't work for you? – Eric Hauenstein Jul 22 '15 at 10:17
  • Did you try to limit the number of users entering your application? – Roman C Jul 22 '15 at 10:38
  • @RomanC I dont want to limit the user, number of users and time taken is not an issue (we have load balancers for that),real issue is user clicking submitting form data again and again. – Govinda Sakhare Jul 22 '15 at 10:44
  • @EricHauenstein I want to know does that example resolves my issues? I bet token interceptor is to avoid refresh and back button based duplicate requests. – Govinda Sakhare Jul 22 '15 at 10:46
  • What is the issue, what did you try to solve it, is the link related to the question you have posted? – Roman C Jul 22 '15 at 10:49
  • That makes it clear piechuckerr. Thank you for the clarification. I suggest you edit the question to indicate that the linked solution may work, but you are uncertain if it is the best approach or something similar. – Eric Hauenstein Jul 22 '15 at 10:49
  • @RomanC the link provided is nothing but token interceptor's example, and that handles refresh based duplicate request, right? but in my scenario after submitting the form, server will take more than 5 minutes to process the request and send response back to client, during these five minutes 'impatient' users may click submit again and again this might create unnecessary overhead.what I want to do is let avoid these duplicate request on server side.someone told me that this can be handled by using token/tokenSession interceptor but I'm not sure. – Govinda Sakhare Jul 22 '15 at 10:59
  • 2
    Check out the Execute and Wait Interceptor: http://struts.apache.org/docs/execute-and-wait-interceptor.html. – Stefan Bartel Jul 22 '15 at 11:11
  • How did you submit the form? – Roman C Jul 22 '15 at 11:31
  • 1
    You want the [Token Session Interceptor](http://stackoverflow.com/a/28717589/1654265). Your assumption about the refresh / back button only is wrong, it works perfectly for double submissions too. From the documentation: `For example, you can use this to prevent careless users who might double click on a "checkout" button at an online store`. Feel free to upvote that answer if it helps. – Andrea Ligios Jul 22 '15 at 11:55
  • I'd just disable the submit button. But there's an *underlying* problem, i.e., your infrastructure should support spikes in traffic. This is a problem faced by any site that has temporary spikes (e.g., flash sales ala Gilt). – Dave Newton Jul 22 '15 at 13:57
  • @RomanC by using html submit button. – Govinda Sakhare Jul 22 '15 at 14:53
  • @DaveNewton I would have did that but my client dont want to disable the button. they want to give users illusion that they're submitting the data. – Govinda Sakhare Jul 22 '15 at 14:58
  • @piechuckerr I didn't get what are you saying. Post a related code example. – Roman C Jul 22 '15 at 15:01
  • @AndreaLigios you're bang on the target, you understood what I want. So you mean if I click submit twice by using 'submit button', interceptor will take care of that? will you give some example/link for referece? please post that in answer section. – Govinda Sakhare Jul 22 '15 at 15:02
  • @piechuckerr Yes. It's all in the answer I've linked in the previous comment: http://stackoverflow.com/a/28717589/1654265 I don't want to rewrite the answer since the problem is exactly the same, this is why I've said *Feel free to upvote **that** answer if it helps* – Andrea Ligios Jul 22 '15 at 15:06
  • Disable it *after* submit... – Dave Newton Jul 22 '15 at 15:07
  • @piechuckerr Feel Free to upvote this answer too :) http://stackoverflow.com/a/20426563/573032 – Roman C Jul 22 '15 at 15:09
  • @Dave: I think he's saying that the client, for some weird reason, wants to make the user think that by pressing the button multiple times, he is sending the request again, while silently all the requests except the first must be swallowed. Don't ask me why... I've seen weirder specs, though :P – Andrea Ligios Jul 22 '15 at 15:11
  • 1
    Well that'd just be wrong. – Dave Newton Jul 22 '15 at 15:17
  • If he uses different token each time the form is submitted then multiple records would be stored. So the service needs to refuse to offer any tokens until the process is finished. Please read my answer and upvote. – Roman C Jul 22 '15 at 15:27
  • @RomanC check the question edit ,this is what I want. – Govinda Sakhare Jul 22 '15 at 15:51
  • @piechuckerr No, you are wrong, it doesn't work in either case. – Roman C Jul 22 '15 at 17:08
  • @RomanC then what do you suggest? final words. I'm going to wrap this question. – Govinda Sakhare Jul 22 '15 at 17:45
  • @AndreaLigios thanx buddy upvoted your answer – Govinda Sakhare Jul 23 '15 at 04:51

1 Answers1

1

You can do several things: a client-side script disabling the submit button after clicked and implement an Execute and wait interceptor, which is great for running long-lived actions in the background while showing the user a nice progress meter.

Anyul Rivas
  • 655
  • 2
  • 12
  • 31
  • 1
    You shouldn't disable a button, users might think they have a problem with the browser or bug in the code. Instead you can apply an animation to show the state when button is in pressed state or in released state. – Roman C Jul 22 '15 at 15:19
  • Or a modal dialog with a message describing the operation – Anyul Rivas Jul 22 '15 at 20:31