JSP =。=请我帮你上传。
<body> <form name="form1" id="form1" action="test" method="post" enctype="multipart/form-data"> <input type="hidden" name="hiddenfield1" value="ok"> Files to upload: <br/> <input type="file" size="50" name="file1"> <br/> <input type="file" size="50" name="file2"> <br/> <input type="file" size="50" name="file3"> <br/> <input type="submit" value="Upload"> </form> </body>
这是我的 TestServlet 包装测试;
公共类TestServlet扩展了HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello<br/>");
boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
out.println("You are not trying to upload<br/>");
return;
}
out.println("You are trying to upload<br/>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> fields = upload.parseRequest(request);
out.println("Number of fields: " + fields.size() + "<br/><br/>");
Iterator<FileItem> it = fields.iterator();
if (!it.hasNext()) {
out.println("No fields found");
return;
}
out.println("<table border=\"1\">");
while (it.hasNext()) {
out.println("<tr>");
FileItem fileItem = it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField) {
out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
"<br/>STRING: " + fileItem.getString()
);
out.println("</td>");
} else {
out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
"<br/>STRING: " + fileItem.getString() +
"<br/>NAME: " + fileItem.getName() +
"<br/>CONTENT TYPE: " + fileItem.getContentType() +
"<br/>SIZE (BYTES): " + fileItem.getSize() +
"<br/>TO STRING: " + fileItem.toString()
);
out.println("</td>");
}
out.println("</tr>");
}
out.println("</table>");
} catch (FileUploadException e) {
e.printStackTrace();
}
}
}
和我的web.xml
Web XML IMAGE HERE
当我运行并上传文件时
我感到错误!
我真的需要你的帮助!!
答案 0 :(得分:0)
从您包含的错误屏幕截图链接中查看。
它说
java.lang.NoClassDefFoundError: 组织/阿帕奇/公地/ IO /输出/ DeferredFileOutputStream
您似乎在Classpath中缺少Apache Commons IO jar,commons-io.jar
。 Commons File Upload取决于它。