Imagine this simple form for uploading a file:
<form action="upload" enctype="multipart/form-data">
<input type="text" name="name"/>
<input type="file" name="file"/>
<input type="submit"/>
</form>
If there is some error (can't copy file, name is not correct...) submitting the form, it must return to the same page, but the file I've selected will be lost. In a large form with several fields that must be validated server side can be very annoying if the user have to select files every time.
Thinking about it, I've find a couple of possible solutions:
Submit form as an ajax request, then go to the next page only if validation is correct. The problem is I must implement something to put every validation error in its place instead of using MVC's features (Spring MVC form tags, in my case).
Submit form. If there is an error, send a page with a "history.back()" in javascript. My file will be there again, but I have no easy way to show validation messages.
I think both solutions are very very clumsy. But selecting the files every time there is a validation error isn't a good solution too.
What do you think? Which solution is better? Is there any good one (preferably without javascript)?
Thanks.
Note: I'm using Spring MVC 3