我已经编写了servlet代码来将照片上传到我的数据库,当我运行页面并尝试上传照片时,我现在得到了Exception
Part filePart = request.getPart("photo");
其中照片名称是在我的表单中输入字段,其代码是
<input type="file" id="photo" name="photo">
和Apache tomcat在浏览器中显示的异常报告是
type: Exception report
message: Servlet execution threw an exception
description: The server encountered an internal error that prevented it from fulfilling this request.
exception:
javax.servlet.ServletException: Servlet execution threw an exception
root cause:
java.lang.AbstractMethodError:org.apache.catalina.connector.RequestFacade.getPart(Ljava/lang/String;)Ljavax/servlet/http/Part;
Uploaddp.doPost(Uploaddp.java:57)
javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
完整堆栈跟踪
Sep 29, 2016 3:44:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Uploaddp threw exception
java.lang.AbstractMethodError: org.apache.catalina.connector.RequestFacade.getPart(Ljava/lang/String;)Ljavax/servlet/http/Part;
at Uploaddp.doPost(Uploaddp.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:0)
没有类型为“文件”。你需要使用multpart / form-data。有关更多信息,请参阅此帖 What does enctype='multipart/form-data' mean? 此外,要在服务器端获取此文件,您需要使用一些库,如此处所述 Convenient way to parse incoming multipart/form-data parameters in a Servlet 另外,请考虑在处理后将这些文件存储在服务器上的位置。用户可能希望下载上传的图像。此外,还有关于这些文件的可访问性的安全性。