开发者

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

开发者 https://www.devze.com 2023-03-23 00:40 出处:网络
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 loos

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 u开发者_如何学JAVApload) 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消