1

I am trying to upload a file using JSP and I got the error as org.apache.jasper.JasperException: An exception occurred processing JSP page /upload.jsp at line 31

28:       upload.setSizeMax( maxFileSize );   
29:       try{   
30:          // Parse the request to get file items.  
31:          List fileItems = upload.parseRequest(request);  
32:   
33:          // Process the uploaded file items  
34:          Iterator i = fileItems.iterator();    

exception that I got is:

javax.servlet.ServletException: java.lang.NoClassDefFoundError:    org/apache/commons/io/output/DeferredFileOutputStream  
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)  
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)  
    org.apache.jsp.upload_jsp._jspService(upload_jsp.java:154)  
Harsha
  • 199
  • 5
  • 20
  • 1
    It seems you forgot put apache commons-io.jar to your project lib. – Georgy Gobozov Nov 20 '13 at 09:45
  • Could you please elaborate on (where is) project lib – Harsha Nov 20 '13 at 09:48
  • @user2686064 you can download it from [here](http://commons.apache.org/proper/commons-io/download_io.cgi) – Jhanvi Nov 20 '13 at 10:00
  • Usually you build web app like war file, then your deploy war on tomcat for example. This war must contain lib directory for external libs(jar files) that you use in your project. If you just try to play with jsp on tomcat put commons-io.jar in tomcat lib directory – Georgy Gobozov Nov 20 '13 at 10:01
  • Yeah I have placed all my .jar files related to commons-io, commons-fileupload into the lib directory of the tomcat. but I still get the same error at the same line – Harsha Nov 20 '13 at 10:05
  • @ Jhanvi I have downloaded those files and kept at tomcat/lib but still the error remains the same. – Harsha Nov 20 '13 at 10:24

1 Answers1

1

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream

This means that the mentioned class is missing in webapp's runtime classpath. As the package name hints, it's part of Apache Commons IO. You need to download the zip file containing the binary JARs, extract it and then drop commons-io.jar in your webapp's /WEB-INF/lib folder, along with the commons-fileupload.jar which you should already have there.

Do not put it in Tomcat's /lib while having the commons-fileupload.jar in webapp's /WEB-INF/lib. Do not fiddle around in project's Build Path setting. Just drop the two JARs in webapp's /WEB-INF/lib and you should be all set.

See also:


Unrelated to the concrete problem, Java code doesn't belong in JSP files. It belongs in Java classes. It's time to learn how to create and use servlets before it's too late.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • That helped me out ... Thank you so much.. could you please help me out in setting the path for upload target in the code I am using Mac, Could you give a statement of code for that.. – Harsha Nov 20 '13 at 12:52
  • You're welcome. As to the subsequent question, check http://stackoverflow.com/questions/18664579/recommended-way-to-save-files-uploaded-to-a-tomcat-servlet If you still stucks, just press "Ask Question" button on the right top. – BalusC Nov 20 '13 at 12:54