aspose file tools*
The moose likes Spring and the fly likes How to handle form re-submission in spring-mvc-3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to handle form re-submission in spring-mvc-3" Watch "How to handle form re-submission in spring-mvc-3" New topic
Author

How to handle form re-submission in spring-mvc-3

Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
Hi,

Any suggestions on how to handle form re-submission in Spring MVC 3 with annotations.
I tried implementing Post-Rediect-Get design pattern but it doesnt work in IE and once Get request crosses it's no. of character in request string it stops working in mozilla as well.
Any tutorial or Blog Or suggestion please.

Thanks,
Mahesh


There is nothing like trying, either you do it or you don't.
SCJP 1.5
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
Anyone to help please.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7



Sounds like you are doing something wrong. What kind of page are you trying to redirect to? Typically it would be a success page or the same page but with a success message. Where all the extra parameters coming from? Post some code so we can see what you are trying to do.


[How To Ask Questions][Read before you PM me]
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
Hi Bill,

Thanks for your reply.

Well, I've a report page getUserDetails.jsp which has form fields such as username, startdate and enddate, producttype.
User fill all these fields clicks on submit. Application displays a report to the user accordingly which is displayed using jqGrid. Therefore I'm passing JSONString to jsp page.
Code looks something like this:



Well, what are the various ways using which we can avoid double form submission in spring mvc 3.0??
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

Well at first glance it looks like when you are posting in you are adding a userlist to the model before redirecting to the get. All of those parameters are going to translate into URL parameters, which is why you are getting the error.

One thing you could do is have the GET method look up the user list and return it rather than having the POST method place it on the model. If you need to pass some additional message information to the page you can also make use of RedirectAttributes.

Typically on the POST method you would either have a BindingResult or a @Valid or implement the Validator interface and only do the redirect if the BindingResult does not have errors otherwise you would return them to the form. Otherwise on an erroneous form submission they will be re-directed and will be unable to rectify the problem.

Below is a blog on using the RedirectAttributes
http://vard-lokkur.blogspot.com.es/2012/02/spring-mvc-flash-attributes.html

Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
Thanks for your reply.

But somehow "redirect:PATH" doesn't work in IE 8.0.7600.16385.
Any specific reason behind that if anyone knows.

Also apart from Post-Redirect-Get pattern is there any other way to handle double submission of form(normal which happens when user refreshes page using F5 or clicking refresh button).

Thanks,
Mahesh
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

redirect works just fine in IE 8 on all of my projects is there a particular exception your are getting? If so please post it. That is the pattern that is used to handle that particular issue. Did you read the link I gave?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle form re-submission in spring-mvc-3
 
Similar Threads
Spring MVC - repopulate the already entered values ?
How do you load the initial command object populated for the initial index.jsp?
Regarding onSubmit method
unicode and form type=text
How to bind data to a Spring form input tag