文件丢失在文件系统中,赶上表单提交 [英] File missing In filesystem, catch on form submit

查看:47
本文介绍了文件丢失在文件系统中,赶上表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要通过jQuery's .ajaxSubmit()函数提交的表格.该表单包含一个文件控件,如果在提交表单之前重命名,删除或以其他方式使所选文件不可访问,则该表单可能会导致失败,这可能是由于失败导致的,这取决于浏览器,该表单可能会也可能不会提交.尽管未能提交是预期的行为,但没有向用户指示表单提交失败或原因,这被认为是制止者.更糟糕的是,在IE中,表单提交时没有任何文件数据.虽然我可以在服务器端了解到这一点,但是如果表单根本不提交,那将是更理想的选择.

I have a form that I am submitting via jQuery's .ajaxSubmit() function. This form includes a file control, and it has been raised as a possible point of failure that if the file selected is renamed, deleted, or otherwise made inaccessible prior to submitting the form, the form may or may not submit based on the browser. While the failure to submit is expected behavior, there is no indicator to the user that the form failed to submit or why, which is being considered a show-stopper. Worse, in IE, the form submits without any file data; while I can catch this on the server side, it would be more ideal if the form did not submit at all.

我知道JavaScript受限制于能够了解有关文件系统的任何信息,并且类似地我知道与跨浏览器兼容性有关的任何事情都存在一些无关紧要的问题.当表单提交失败或jQuery吞下它时,Firefox似乎没有引发任何异常. IE浏览器显然会蹒跚前进.我想看看是否有一种方法可以捕获表格未提交或使用无效文件提交的事实.我还想捕获提交前文件字段是否存在问题.

I am aware that JavaScript is restricted in being able to know anything about the filesystem, and I am similarly aware that there are some not-insignificant issues with anything having to do with cross-browser compatibility. Firefox doesn't seem to throw any kind of exception when the form submission fails, or jQuery is swallowing it. IE toddles along obliviously. I would like to see if there is a way to capture the fact that the form did not submit or submitted with an invalid file. I would also like to capture if there is a problem with the file field prior to submission.

有什么想法吗?

推荐答案

您始终可以使用Struts2 fileUpload拦截器应用于设置File提交表单时反对您的行为.一旦获得了对象,但它不是null,则可以进行某种验证.例如file.exists().

You can always use the Struts2 validation framework to validate the file object. Apply fileUpload interceptor to your action that sets the File object to your action when you submit the form. Once you get the object and it's not null you may proceed with some kind of validations. For example file.exists().

这篇关于文件丢失在文件系统中,赶上表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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