在Java中回发保留文件内容 [英] Retaining File Content on Postback in Java

查看:69
本文介绍了在Java中回发保留文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Struts2 / spring集成应用程序中有一个文件上传解决方案。

我对用户选择的文件进行了验证。如果用户选择了3个文件,其中1个未通过验证,我将用户返回到同一个上传页面。



我的问题是,对于其他两个文件经过文件验证我不能保留回发时的内容(文件路径)(当我返回上传页面时出错)由于浏览器的安全原因。


现在我将它们存储在会话中。但是jvm可能会崩溃。

有没有更好的方法来实现它?

I have a file upload solution in Struts2/spring integrated app.
I have a validation for the files the user selects. if the user selected 3 files and 1 of them fails validation, i return the user back to the same upload page.

My problem is, for the other two files that went through the file validation I cannot keep the content(file path) on postback (when i return to the upload page with error)due to security reasons for browsers.

Right now I am storing them in the session. But jvm might crash with this.
Is there a better way to implement this ??

推荐答案

你好,



您应该在后台执行此类任务作为异步批处理作业。一种简单的方法是使用Quartz Scheduler并用于验证文件内容。这样,用户无需等待验证完成。预定作业通常使用数据库来跟踪进度。您可以在此表上构建一个视图,以便用户可以找到他们上传的内容。

但是,如果必须以同步方式执行此操作,则无需将成功验证文件的文件内容保留在任何位置。只需将名称保存在会话变量中即可。在回发时使用会话中的值来跳过已检查文件的验证。出于安全原因,您可能还需要计算校验和并存储它们。这样,如果新旧校验和不匹配,则可以重新验证文件。验证成功后,您可以从会话中删除此变量。



问候,
Hello,

You should do such task in background as a asynchronous batch job. One simple way is to use Quartz Scheduler and use to validate the file contents. This way user does not have to wait for the validation to complete. The scheduled job will typically use the database to keep track of progress. You can build a view over this table so that users can find out what happened to their uploads.
However if you must do this in a synchronous manner, then there is no need to keep the file contents of successfully validated files anywhere. Just keep the names in a session variable. On postback use values from session to skip validations of already checked files. For safety reasons you may also want to compute the checksums and store them as well. This way if new and old checksums do not match then you can re-validate the files. Once the validation is successful you can remove this variable from session.

Regards,


这篇关于在Java中回发保留文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆