• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

submitting the invoice twice when submitt button is clicked

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

i have a JSP where i have some buttons and specially i have submit button of type button when the user presses this submit button very rarely in production it is submitting twice but i tried to recreate the problem in my test server but unable to create,i dont why know it is happening only in production and it is rare the following is the way how we handled to disable the buttons when it is clicked



<span class="button-blue HideInPrint"><input type="button" name="sButton" value="Submit" onclick"javascript:continueAction('submit');" <%=buttonStatus%> /></span>
<input type="hidden" name="submitButton" value="" />


function continueAction(typeOfAction)
{

disableButtons();
//Populate the appropriate hidden field that will be passed to the servlet,
//depending on the type of action performed on the page
if (typeOfAction == "submit") {
document.billSumm.submitButton.value="Submitted";
} else if (typeOfAction == "save") {
document.billSumm.saveAsDraft2.value="Saved";
}
else if (typeOfAction == "cancel") {
document.billSumm.cancel.value="Cancelled";
}

//Invoke submission
document.billSumm.submit();

}

function disableButtons()
{

if (document.all || document.getElementById) {
for (i = 0; i < document.billSumm.length; i++) {
var tempobj = document.billSumm.elements[i];
if (tempobj.type.toLowerCase() == "button")
tempobj.disabled = true;

}
}
}

please advice when does this problem occur and how over come it.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know for sure it is the application submitting twice and not the user?

Regards

Matt
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,

thanks for your response, when the user submits an invoice the application generates a unique reference number and puts the enitre data on a MQ Queue of concerned to that refernce number later which is submitted to MVS DB
we confirm that application is generating as it is putting the message twice in the MQ queue for the same Reference Number
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not rely on users to do what they are told, so they may submit more than once.
You can not rely on javascript to prevent them submitting more than once.

However, you can rely on the server not processing duplicate requests if you plan for it. Have a search for 'Synchronizer Token pattern' and you'll find some good descriptions and solutions for the problem.
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darren,

its a good idea from you, but it is built feature of Struts and my application is not based on struts just we have servlets and jsp's and i cannot change the flow as it in maintainence so can you suggest how can i implement this Synchronizer Token pattern

thanks
 
Darren Edwards
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not exactly what the pattern describes, but could work in your case.

In your control (servlet) code, generate a random String - this is your token. Add the token into the user session.


Within your form add a hidden field called token which contains the token from the session.


In your control (servlet) code that processes the form you should check the hidden parameter 'token' matches the 'token' attribute stored in the user session. If it does, then remove 'token' attribute from the user session and process the form. If 'token' does not match, or does not exist in the session, you know it is a duplicate request.
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darren,

Thanks for your reply.


have a nice week end
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darren,

servlet where iam creating a string randomly
Double d = new Double(Math.random());
String token = d.toString();
session.setAttribute("token", token);


in the JSP
<input type="hidden" name="token1" value="${sessionScope.token}" />

and in the control servlet which fires when the jsp is submitted
StringstrJspToken = request.getParameter("token1");
String strToken = (String) session.getAttribute("token");
if strToken.equals(strJspToken)

i have tested with System.out.println and found that iam not getting value from Jsp hidden variable please can u suggest is there any mistake in my code

thanks
 
Darren Edwards
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the HTML page contains a value for token1 and if the parameter name is correct in the processing servlet then I am guessing that

does not appear within
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Darren

i tried by keeping input tag not within <form> </form> in the Jsp
then also iam not getting iam not understanding why it is not getting the value.

Thanks
 
Darren Edwards
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From your descriptions it seems more likely a HTML error than anything else. Can you post a HTML version (view source -> copy from within IE) of the page that displays the form? Make sure you strip out anything confidential or private domain names first though!
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Dareen,

i looked in to the apllication closely and got to know that the value which i have set in Session
With in JSP iam not getting the session String variable in to hidden variable at all
<input type="hidden" name="token1" value="token" /> is not working is there any other way

thanks for continous support
 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Darren,
i got the problem and cleared
thanks for your solution
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic