简体   繁体   English

解析多部分表单数据时的异常

[英]exception when parsing multipart form data

I am trying to handle a file upload, and I'm using the com.oreilly.servlet.multipart.MultipartParser class to parse the posted data (in cos.jar). 我正在尝试处理文件上载,并且正在使用com.oreilly.servlet.multipart.MultipartParser类解析发布的数据(在cos.jar中)。 However, when I call the constructor for MultipartParser, I get this exception: 但是,当我为MultipartParser调用构造函数时,出现以下异常:

java.io.IOException: Corrupt form data: premature ending
    at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:166)
    at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:94)

Has anyone seen this before? 谁看过这个吗? From what I read, this means that the data ended before it found the boundary it was looking for. 根据我的阅读,这意味着数据在找到所需边界之前就结束了。 How can I fix this? 我怎样才能解决这个问题?

I am using cos.jar version 1.0. 我正在使用cos.jar 1.0版。

Thanks! 谢谢!

http://www.servlets.com/cos/faq.html http://www.servlets.com/cos/faq.html

This indicates there was a problem parsing the POST request submitted by the client. 这表明解析客户端提交的POST请求时出现问题。 There can be many causes for the problem: 可能有很多原因导致此问题:

  • The client hit the STOP button (not really a problem, but it does cause a premature ending) 客户端按下STOP按钮(这不是真正的问题,但确实会导致过早结束)
  • A bug in the web form 网络表单中的错误
  • A bug in the servlet Servlet中的错误
  • A bug in the web server Web服务器中的错误
  • A bug in the browser 浏览器中的错误
  • A bug in the com.oreilly.servlet library itself com.oreilly.servlet库本身中的错误

History has shown the web server to be the most frequent cause of problems probably because there are so many different servers and few vendors appear to test their binary upload capability. 历史表明,Web服务器是造成问题的最常见原因,可能是因为有太多不同的服务器,并且很少有供应商来测试其二进制上传功能。

First, make sure your client isn't hitting the STOP button. 首先,请确保您的客户未按下“停止”按钮。 Then, check if your problem is already posted on the "Servlet bugs you need to know about" resource on this site. 然后,检查您的问题是否已经发布在此站点上的“您需要了解的Servlet错误”资源上。 If it's not well known, then you get to be among the first to learn about it! 如果它不为人所知,那么您将成为第一个了解它的人! And you can share your discovery with us here! 您可以在这里与我们分享您的发现!

Second, see if the upload works using the provided upload.html form and DemoRequestUploadServlet.java class. 其次,使用提供的upload.html表单和DemoRequestUploadServlet.java类查看上传是否正常。 Some people have found bugs in their form that caused problems. 有些人发现了导致问题的错误形式。 Testing this combination will see if that's the case. 测试此组合将查看情况是否如此。 One user, Duke Takle, found this exception was caused by a redirect: I was experiencing the same "premature ending" as Albert Smith. 一个用户,塔克尔公爵(Duke Takle)发现此异常是由重定向引起的: 我遇到了与阿尔伯特·史密斯相同的“过早结束”。 What I've found is that the problem was isolated to IE 5.0. 我发现问题出在IE 5.0。 The application that troubled me was doing a redirect after the construction of a MultipartRequest. 困扰我的应用程序在构造MultipartRequest之后执行重定向。 It looks like this construction went well except on IE 5.0 the browser attempted to make the request again and by that time the ServletInputStream was empty. 看起来这种构造进行得很好,只是在IE 5.0上,浏览器尝试再次发出请求,而那时ServletInputStream为空。 I've modified the application to simply write the needed response instead of redirecting. 我已经修改了应用程序以仅编写所需的响应而不是重定向。 This problem was observed and fixed as described in Tomcat 4.0 and Weblogic 6.1. 如Tomcat 4.0和Weblogic 6.1中所述,已观察到并解决了此问题。 Other users have found bugs in their handling servlet where they call request.getParameter() instead of multipartRequest.getParameter(), and some servers falsely read the input stream when their getParameter() is called causing an "unexpected end of part". 其他用户在处理servlet时发现错误,他们调用request.getParameter()而不是multipartRequest.getParameter(),并且某些服务器在调用getParameter()时错误地读取了输入流,从而导致“部件的意外末尾”。

So, the problem was caused by me calling the MultipartParser constructor twice, by accident. 因此,问题是由我偶然两次调用MultipartParser构造函数引起的。 It failed the second time, since the request had already been processed. 由于请求已被处理,因此第二次失败。

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

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