You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Reynolds <jr...@digijam.org> on 2003/09/19 04:15:40 UTC

Refreshing Form Submission and Duplicates

Hi,
 
I have a question about a bug in my application using a Struts Form.
This happens in multiple areas of my site, but the one example I will
use is a Message Board feature. The problem is that when a user goes to
a list of messages, fills out the form to post a message and ends up
back on the list page, the message will be submitted twice if they
refresh the page following the form submission. this has caused
duplicate messages throughout the message board, as it is the nature of
message boards to refresh the list of messages often to check for new
ones. Keep in mind, my app strictly follows the approach of the O'Reilly
book.
 
I'll try to make this easy to follow:
 
1. the user goes to a message board with a list of messages from other
users. this page is /messagelist.do the action looks like this:
 
      <action 
            path="/messagelist" 
            name="messageListForm" 
            type="myapp.framework.actions.MessageListAction" 
            scope="request">
            <forward name="Success" path="/templates/messagelist.jsp"/>
      </action>
 
(the "messageListForm" is a struts form bean with a List of message
objects)
 
2. at the bottom of the page is a form to post your own message 3. the
user enters their Name, Subject and Message Body and submit the form 4.
the form is processed by a Struts Action. the action tag in
struts-config.xml looks like this:
 
      <action 
            path="/messageinsert" 
            name="messageDetailForm" 
            type="myapp.framework.actions.MessageInsertAction" 
            scope="request" 
            validate="false">
            <forward name="Success" path="/messagelist.do"/>
      </action>
 
- From the naming convention, you can see that the Action inserts the
message into storage (database) and upon success the user is forwarded
to the same /messagelist.do action
 
Now, when the form is submitted and this is displayed, the URL in the
browser says:
 
http://myapp.com/myapp/messageinsert.do
 
I expect that this is correct because the HTML form itself was <form
action="/messageinsert.do" method="POST">.
 
The user's submitted message will be found on the list of messages.
HOWEVER, IF THEY REFRESH THE SCREEN, THE MESSAGE WILL BE SUBMITTED
AGAIN. This should not happen. If i'm the customer, i've already
submitted the form, and now i'm seeing a list of messages. refreshing
should have no effect on the form that i just submitted.
 
Does anyone have a suggested fix?
 
Thanks all,
 
JR