Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with file upload in jsp [duplicate]

I want to uploal a doc file to the servlet using commons-fileupload-1.2.2.

I'm using this code in the front end:

<form action="fileuploader" method="post" enctype="multipart/form-data">
<br>File : <input type="file" name="uploadedFile">
<br><input type="submit">

and using this code in the servlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
}

but system gives me a this error

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)

I think problem is in this line:

boolean isMultipart = ServletFileUpload.isMultipartContent(request);

Help me with this please

like image 699
Lakshitha Herath Avatar asked Dec 16 '22 09:12

Lakshitha Herath


1 Answers

You need to drop the commons-fileupload.jar and commons-io.jar files in /WEB-INF/lib folder of your webapp project. This folder becomes ultimately part of webapp's runtime classpath. Note that in a bit decent IDE like Eclipse/Netbeans/IntelliJ, you do not need to fiddle with buildpath properties afterwards. The IDE is perfectly aware that libraries in /WEB-INF/lib are to be taken part of the runtime classpath, so it adds that to the build path automagically.

like image 149
BalusC Avatar answered Jan 26 '23 00:01

BalusC