繁体   English   中英

多部分/表单数据表单提交

[英]Multipart/form-data form submit

在IE9中,当我向Java Servlet提交带有文件的表单(enc类型:multipart / form-data)时,出现了问题。 我很难找到错误并找到解决方案。 不工作时,Content-Length为0。 这是请求标头中的唯一区别。 并且请求消息中没有任何区别。

我如何尝试在java serlvet中检索表单数据(使用org.apache.commons):

ServletFileUpload upload = new ServletFileUpload();
if (!ServletFileUpload.isMultipartContent(request)
    throw new Exception("Invalid parameters");
FileItemIterator itr = upload.getItemIterator(request);
while(itr.hasNext()
{
    // This never gets run when the error occurs (Content-Length: 0).. 
}

我认为表单提交有问题吗? 有人知道什么地方可能出问题吗? 在Chrome中,它始终有效。

更新:html表单的基本部分:

<form name='uploadparticipants' action='ParticipantUploader' method='post' encoding='multipart/form-data' enctype='multipart/form-data' target='upload_target' onsubmit='admin.uploadCourseParticipants()'>
// Some input fields inside a table, among them a file input //
<input type='submit' value='somevalue'>
</form>
  1. 请确保您在表单创建过程中已明确添加method="post"
  2. 另外,当使用Javascript在Internet Explorer(6和7)中动态创建表单时,由于某种原因,还需要设置编码属性。 因此,尽管该属性称为enctype,但是设置enctype不会执行任何操作。 请尝试添加以下代码:

    form.setAttribute('encoding','multipart / form-data');

暂无
暂无

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

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