[英]Java Fileupload getParts() return Files and a null value
I'm trying to create a fileupload. 我正在尝试创建一个fileupload。 My file input: 我的文件输入:
<input class="form-control" name="file" type="file" size="20" accept="application/pdf, image/jpeg, image/png, text/plain" multiple >
And this for-loop in the servlet iterate over the Parts to get their total size. 并且servlet中的for循环遍历Parts以获得它们的总大小。 It iterate over the selected files and a additional element with size 1 and content type null
. 它迭代所选文件和大小为1且内容类型为null
的其他元素。 This cause an errror. 这导致错误。
for (Part part : request.getParts()) {
System.out.println("Dateigrösse: " + part.getSize());
uploadSize = uploadSize + part.getSize();
System.out.println("Dateityp: " + part.getContentType());
if(part.getContentType().equals("application/pdf") || part.getContentType().equals("text/plain") || part.getContentType().equals("image/jpeg") || part.getContentType().equals("image/png")) {
} else {
types = false;
}
}
First it worked, but know there's this null element. 首先它工作,但知道有这个null元素。 What should I do? 我该怎么办? Where does it comes from? 它来自哪里? I don't change anything. 我什么都没改变。 I'm using the code from oracle EE7 doc and a famous online article. 我正在使用oracle EE7 doc中的代码和一篇着名的在线文章。 I don't change anything before this for-loop. 在这个for循环之前我没有改变任何东西。
Thank you in advance. 先感谢您。
The getParts() returns all named Inputs too. getParts()也返回所有命名的Inputs。 So it returns me the choosen subject as a Part. 所以它将选择的主题作为一个部分返回给我。 Now i'm filtering for inputs named "file". 现在我正在过滤名为“file”的输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.