gpt4 book ai didi

jquery - 从 Struts 2 文件上传实用程序发布 ajaxForm 在 IE 中不起作用

转载 作者:行者123 更新时间:2023-12-03 06:38:11 24 4
gpt4 key购买 nike

背景:我正在寻找一个使用 Ajax + Struts 2 异步上传大文件的工具,我能够使用 servlet 执行相同的操作,但是当我修改逻辑以调用 Struts 操作时。我注意到,当我尝试使用 Struts 2 操作上传大文件时,它不会从 jQuery ajaxForm(options);

调用

我已经使用了下面链接中指定的示例代码,效果非常好。 http://www.simplecodestuffs.com/file-upload-with-progress-bar-using-jquery-in-servlet/

任何人都可以判断下面的 jQuery 函数调用对于上传功能是否正确。

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

我尝试过,但当上传大量数据时,它在某个特定浏览器中无法按预期工作。(也就是说,发生了客户端ajax调用,但是后端没有调用相应的Struts 2操作,服务器端没有生成日志)。

我无法理解为什么当 jQuery ajaxform 上传大文件(分段上传功能)时,没有调用 Struts 2 操作。

jQuery:

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

JSP 片段:

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

提出类似问题here .

最佳答案

将大文件上传到 Struts2 操作的问题是请求可能不符合 Struts2 默认使用的限制。在配置设置中,该值设置为 2097152。您还可以设置每个操作的限制。有关更多信息,您可以在 Struts2 File Upload - Advanced Configuration 中找到:

The Struts 2 default.properties file defines several settings that affect the behavior of file uploading. 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
<小时/>

此文档页面的下一部分是 File Size Limits您已经注意到下划线框架(struts2、commons-fileupload)使用的文件大小的限制:

There are two separate file size limits. First isstruts.multipart.maxSize which comes from the Struts 2default.properties file. This setting exists for security reasons toprohibit a malicious user from uploading extremely large files to fileup your servers disk space. This setting defaults to approximately 2megabytes and should be adjusted to the maximum size file (2 gigs max)that your will need the framework to receive. If you are uploadingmore than one file on a form the struts.multipart.maxSize applies tothe combined total, not the individual file sizes. The other setting,maximumSize, is an interceptor setting that is used to ensure aparticular Action does not receive a file that is too large. Noticethe 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>
<小时/>

如果文件大小超过上述配置设置,伪进度条一返回响应就停止。它可能是 1% 或 100%,这取决于脱粒速度和文件大小。但在服务器端您可能会看到异常

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

以及以下警告。如果不超出框架本身的限制,您可以调整框架的文件大小限制。

关于jquery - 从 Struts 2 文件上传实用程序发布 ajaxForm 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38093885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com