This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Multiple submits and Struts framework

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

Can Struts handle multiple submits (i.e. handling more than one requests sent from the same page)? Multiple submits occur, for example, when the user clicks one button more than once.

There is way to disable a button after one click with Java script (client side implementation). Also there is a way to catch multiple submits on the web server side (server side implementation). But the problem with the latter is that the response to the original request gets lost.

Thanks a lot in advance.
[ May 18, 2004: Message edited by: Alex Sharkoff ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts has a "session token" based implementation for preventing double-submits. I don't think it prevents your "first request's response is lost" problem, though.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lasse,

Does the session token mechanism implemented and applied automatically? Do I need to set anything in the configuration file (like validation), or it really did all things in auto?

In addition, if not, are there any code example?

Nick
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
Does the session token mechanism implemented and applied automatically? Do I need to set anything in the configuration file (like validation), or it really did all things in auto?


No, it doesn't get applied automatically. You need to call Action#saveToken(HttpServletRequest) in your Action class to mark the start of a "transaction" you want to be submitted only once. Then, when you're ready to submit the transaction, call Action#isTokenValid(HttpServletRequest, boolean) to determine whether the transaction token is still valid (if it isn't, you know that the transaction has been processed once already).

Disclaimer: I have only written some practice code using this technique so I'm not sure how well it suits real-world situations.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Action provides following vey useful methods to do this :
* isCancelled(HttpServletRequest request) { return false;}
* isTokenValid(HttpServletRequest request) { return false;}
* isTokenValid(HttpServletRequest request, boolean reset) { return false;}
* resetToken(HttpServletRequest request) { }

Here is the code sample. Implement this in your base action class.
==========================================================================
if (form instanceof BaseActionForm &&
"true".equalsIgnoreCase( ( (BaseActionForm) form).getUseToken()))
{
if (isTokenValid(request)||
(request.getSession().getAttribute(Globals.TRANSACTION_TOKEN_KEY) == null)) {
forward = processCurrentRequest(mapping, form, request, response);
}else {
resetToken(request);
request.setAttribute("errorkey", "error.generic.1");
forward = ERRORPAGE;
}
} else { //Use Token is set to false (default) or not of type BaseActionForm
forward = processCurrentRequest(mapping, form, request, response);
}
===========================================================================
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But then, if there are 10 actions that the system needs to serve, I need to write the checking code for 10 times?

Since each time we may need to handle different things, and focus on different areas, are there any methods that are declarative, not programmatic?

Nick
 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't think it is possible to implement the declarative token control,because it is embended witin your code,the machanism for token control is a little like the transaction control that the code is enclosed in the "begin..............commit" block,this machanism can give you more progem flexibility.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
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