I have a jsp page that allows a user to enter their details for creating an account. When the user hits submit I call createNewMember.do - this action class inserts the details of the user into the database. When it has finished it returns a findForward value of "success". Struts config maps this to the userHome.do action class. This page will retrieve user data and send beans to to displayUserHome.jsp. (as it is a new user it will be mostly empty for now).
The problem I am having is that when the displayUserHome.jsp shows, the url that displays is createNewMember.do and not userHome.do - I believe this is the case because I have chained the two action files in struts-config.xml. This means that if the user refreshes the screen the logic to create a new user is executed again!
Is there an attribute that I can use to prevent this in the struts-config.xml file.
If your concern is with "duplicate submission of a form" (user pressing refresh) then struts does provide something called "Tokens" which you might be interested in using.
Unfortunately, I have never used it, but I remember seeing a post about it in this forum. Try searching for it using "Token". Hopefully someone more knowledgeable will come along and help you.
Originally posted by david allen: The problem I am having is that when the displayUserHome.jsp shows, the url that displays is createNewMember.do and not userHome.do - I believe this is the case because I have chained the two action files in struts-config.xml. This means that if the user refreshes the screen the logic to create a new user is executed again!
Try setting the attribute redirect="true" for the <forward/> that takes the user from createNewMember.do to userHome.do. That'll effectively do a HTTP 302 redirect instead of a server-side forward and the browser's location bar should be showing "userHome.do".
There are two ways as the above two mentioned ...............in the second scenario where if u make redirect=true ur request attributes wont be available to the next jsp/action as it makes a roung trip to the client and struts provide tokens which store a variable in session and this eliminates the duplicate submission of the form
so depending on the data u can decide up on which to use..i feel redirect is better if u dont have much data to store in request as this will also avoid resubmission if the user clicks back button also