文件上傳我想用公地文件上傳-1.2.2 uploal一個doc文件到servlet。問題在JSP
我使用在前端驗證碼:
<form action="fileuploader" method="post" enctype="multipart/form-data">
<br>File : <input type="file" name="uploadedFile">
<br><input type="submit">
,並在servlet使用此代碼:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
}
但系統給了我這個錯誤
SEVERE: Servlet.service() for servlet FileUploaderServlet threw exception java.lang.ClassNotFoundException: org.apache.commons.fileupload.servlet.ServletFileUpload at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) at org.jspFileUploader.fileUploader.FileUploaderServlet.doPost(FileUploaderServlet.java:31) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 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:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)
我認爲問題是在這一行:
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
幫助我這個請
我正在使用Tomcat 6和commons-fileupload-1.2.3.jar,並且將它添加到「Java構建路徑」中的庫中。並且我將這個jar導入到servlet中,像這樣輸入org.apache.commons。 import org.apache.commons。上傳文件。*; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.disk.DiskFileItemFactory; 這些進口沒有給出任何error.Do我需要做的另一個配置? –
當你說「在'Java build path'中添加了這個庫'」時,我想你正在談論你的IDE(例如關於Eclipse)。你的IDE配置!=你的TOMCAT配置!您需要將.jar複製到Tomcat。您的IDE可能有助於自動執行這些任務,但我鼓勵您瞭解如何手動配置Tomcat,而不依賴於IDE。在你的情況下,只需將「commons-fileupload-1.2.3.jar」複製到$ CATALINA_BASE/conf – paulsm4
@ paulsm4通常應該將lib複製到'WEB-INF/lib'而不是'tomcat/lib'。然而,+ 1.這似乎是問題... – home