简体   繁体   中英

Spring 3 MVC File Upload and Form Validation without losing the file

Is there a small framework for Spring 3 & JSP that allows server side form validation for forms that contains normal fields and file upload, which is able to "rejecting" the request without loosing the uploaded file?

In more Detail: I have a HTML Form that contains normal input fields and a file upload field. The validation of this form is done on server side (it is to complex to do it on client side). There is no problem if the form data is correct. But the user sends a invalid form then I need to display the form again, the user corrects the input and send the form again. That works fine except the fact that the user needs to enter (and upload) the file again. -- The solution in general is simple: I need to store the file on server side and then use this already uploaded file if the user sends the corrected data again. -- But even if it is not so complicated it is a lot of work, and I do not want to reinvent the wheel.

So my question is, is there any small framework that implement this feature, which I can add to my application?

( At the moment I use: Spring 3.0, JSP, Dojo )

All you really need to do is save the file and associate it with the session, and not to rely on automatic or injected validations which would reject the request without allowing you to save the file first - programmatic validation. Save the file with some kind of association to the session (or the user, if using Spring Security, for example) so it can be used in future requests.

But: that desired solution requires you to establish some offline cleanup of files. I have a similar situation where a process creates a (permanent) "temp" table. When the table is created, I kick off a table watcher process annotated with @Async that loops and sleeps the thread for an hour, checking to see if the table still exists (its deleted by the end of the online process). If the table is still present after an hour, the async thread deletes it and exits. In your case, you need to establish 1) what to check for to see if the user has completed the process, and 2) how long to check for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM