java - 为什么使用“multipart/form-data”上传文件时经常出现异常?
问题描述
我在form中使用enctype="multipart/form-data"提交文件。但是在没有文件上传的情况下,经常报异常。
org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.warn:68 - Unable to parse request
org.apache.commons.fileupload.FileUploadException: early EOF
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
Caused by: org.eclipse.jetty.io.EofException: early EOF
at org.eclipse.jetty.server.HttpInput.read(HttpInput.java:65)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at org.apache.commons.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:134)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:999)
我调试 jar,发现 MultipartStream.skipPreamble() 中抛出了异常
public boolean skipPreamble() throws IOException {
// First delimiter may be not preceeded with a CRLF.
System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2);
boundaryLength = boundary.length - 2;
try {
// Discard all data up to the delimiter.
discardBodyData();
// Read boundary - if succeeded, the stream contains an
// encapsulation.
return readBoundary();
} catch (MalformedStreamException e) {
return false;
} finally {
// Restore delimiter.
System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2);
boundaryLength = boundary.length;
boundary[0] = CR;
boundary[1] = LF; //here!!!!this line will throw a IOException
}
}
我很困惑,但我无法稳定地重现它,因为问题存在,然后它不存在。有没有人遇到过这个问题?
解决方案
推荐阅读
- javascript - 如何计算从 12am 到 12am 的日期之间的差异?
- c# - 以 VBA 形式显示 C# 生成的位图
- javascript - 为什么在使用 Async await 和 mongodb 时 Api 响应很慢
- cmd - 在一行上获取命令提示符
- python - 如何打印用户通过输入选择的列表?
- android - 房间上可以为空的外键
- apache - 我在执行出错时使用 jmeter 进行性能测试,任何人都可以建议我
- node.js - 如何处理 puppeteer 对没有 id 的 Html 标签的关注,多个和隐藏类的问题
- php - API 不返回数据
- javascript - Javascript异步如何等待不同数量的uploadTasks全部完成?