简体   繁体   English

从Struts2文件上传实用程序发布ajaxForm在IE中不起作用

[英]Post ajaxForm from Struts2 file upload utility not working in IE

Background: I am looking for a tool to upload big file asynchronously using ajax + Struts2, I was able to do the same thing using servlet but when I modify the logic to call struts action. 背景:我正在寻找一种使用ajax + Struts2异步上传大文件的工具,我能够使用servlet进行相同的操作,但是当我修改逻辑以调用struts操作时。 I have noticed that when I try to upload a huge file using struts2 action, it doesn't get called from jquery ajaxForm(options); 我注意到当我尝试使用struts2动作上传大文件时,不会从jquery ajaxForm(options);调用它ajaxForm(options);

I have used the sample code specified on the below link this works perfectly fine. 我使用了以下链接上指定的示例代码,效果很好。 http://www.simplecodestuffs.com/file-upload-with-progress-bar-using-jquery-in-servlet/ http://www.simplecodestuffs.com/file-upload-with-progress-bar-using-jquery-in-servlet/

Can anyone tell if below jquery function call is correct for upload functionality. 谁能告诉下面的jquery函数调用是否正确用于上传功能。 $("#uploadtest").ajaxForm(options);

I tried but it is not working as expected in one particular browser when huge data is uploaded. 我试过了,但是当上传大量数据时,它无法在一种特定的浏览器中正常工作。 (That is, client ajax call occurs, however, the corresponding struts2 action is not getting called in the backend, logs are not generated on the server side). (也就是说,发生了客户端ajax调用,但是,后端未调用相应的struts2操作,服务器端未生成日志)。 I am not able to understand why struts2 action is not getting called when jquery ajaxform to upload huge file (multipart upload functionality). 我不明白为什么当jquery ajaxform上传大文件时,为什么没有调用struts2动作(分段上传功能)。

jquery $("#uploadtest").ajaxForm(options); jQuery $("#uploadtest").ajaxForm(options);

jsp snippet <s:form id="uploadtest" name="uploadform" action="aStrutsAction" method="post" enctype="multipart/form-data"> jsp片段 <s:form id="uploadtest" name="uploadform" action="aStrutsAction" method="post" enctype="multipart/form-data">

Similar question is asked here .. FormData in IE8/9 在这里问类似的问题.. IE8 / 9中的FormData

The problem with uploading big files to the Struts2 action is that request may not comply the limits used by default with Struts2. 将大文件上传到Struts2操作的问题是请求可能不符合Struts2默认使用的限制。 In configuration settings the value is set to 2097152. You can also set the limits per action. 在配置设置中,该值设置为2097152。您还可以设置每个动作的限制。 More about it you can find in Struts2 File Upload - Advanced Configuration : 您可以在Struts2文件上载-高级配置中找到更多相关信息:

The Struts 2 default.properties file defines several settings that affect the behavior of file uploading. Struts 2 default.properties文件定义了一些影响文件上传行为的设置。 You may find in necessary to change these values. 您可能会发现有必要更改这些值。 The names and default values are: 名称和默认值是:

 struts.multipart.parser=jakarta struts.multipart.saveDir= struts.multipart.maxSize=2097152 

The next section from this docs page is File Size Limits where you have noticed about limitations of the file size used by the underline frameworks (struts2, commons-fileupload): 该文档页面的下一部分是文件大小限制 ,您在其中注意到下划线框架(struts2,commons-fileupload)使用的文件大小的限制:

There are two separate file size limits. 有两个单独的文件大小限制。 First is struts.multipart.maxSize which comes from the Struts 2 default.properties file. 首先是struts.multipart.maxSize它来源于Struts 2的default.properties文件。 This setting exists for security reasons to prohibit a malicious user from uploading extremely large files to file up your servers disk space. 出于安全原因,存在此设置是为了禁止恶意用户上传非常大的文件来填充服务器磁盘空间。 This setting defaults to approximately 2 megabytes and should be adjusted to the maximum size file ( 2 gigs max ) that your will need the framework to receive. 此设置的默认值约为2兆字节,应将其调整为您需要框架接收的最大文件大小(最大为2 gigs )。 If you are uploading more than one file on a form the struts.multipart.maxSize applies to the combined total, not the individual file sizes. 如果要在一个表单上上传多个文件,则struts.multipart.maxSize适用于合并的总数,而不适用于单个文件的大小。 The other setting, maximumSize , is an interceptor setting that is used to ensure a particular Action does not receive a file that is too large. 另一个设置maximumSize是一个拦截器设置,用于确保特定的Action不会收到太大的文件。 Notice the locations of both settings in the following example: 在以下示例中,请注意两个设置的位置:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.multipart.maxSize" value="1000000" /> <action name="doUpload" class="com.example.UploadAction"> <interceptor-ref name="basicStack"/> <interceptor-ref name="fileUpload"> <param name="maximumSize">500000</param> </interceptor-ref> <interceptor-ref name="validation"/> <interceptor-ref name="workflow"/> <result name="success">good_result.jsp</result> </action> </struts> 

If the file size exceeds the above configuration settings, the pseudo progress bar stops as soon as it returns a response. 如果文件大小超过上述配置设置,则伪进度条将在返回响应后立即停止。 It could be 1% or 100% it depends on thresh speed and a file size. 它可以是1%或100%,具体取决于脱粒速度和文件大小。 But on the server side you might see an exception 但是在服务器端,您可能会看到一个异常

org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (xxx) exceeds the configured maximum (yyy)

and the following warnings. 以及以下警告。 You might adjust the file size limitations with the framework if it doesn't exceed the framework's limitations itself. 如果框架本身没有超出文件限制,则可以调整文件大小限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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