Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and URLs

 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

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.

Thank you for your help.
david
 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Sheldon Fernandes
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic