Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No class def found error in apache commons fileupload

 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am using apache commons file upload for uploading file from servlet.
i hv put the jar file in tomcat/common/lib n set the classpath accordingly.
i get my code complied but it gives following exception at run time:

message
Internal Server Error

description
The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)................................................................................

root cause
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
at upload.doPost(upload.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve....................................................................................

code which i used is :
boolean isMultipart = FileUpload.isMultipartContent(request);
out.println(isMultipart);
try {
List l = fu.parseRequest(request);
Iterator i = l.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem)i.next();
String filename = fi.getName();
if(!fi.isFormField()) {
System.out.println("\nNAME: "+fi.getName());
System.out.println("SIZE: "+fi.getSize());
}
catch (Exception e) {out.println(e);}

pls help me....
thanks in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the jar file again, maybe it got corrupted.

BTW: Although putting libs in common/lib will work, it's not the best place for them. common/lib is a placeholder for libraries that are used by Tomcat itself. If you want to share one library among all your apps, you can do this by putting it in /shared/lib.

I, personally, prefer to keep them all under WEB-INF within each app, even if this means having multiple copies of the same lib.
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ben,
there was some minor classpath error which i sorted out.
thanks for ur help
Now i can upload the file and write it in some directory but can you pls guide me wat should be done to write it into a database?
regards
Khushi
[ March 02, 2005: Message edited by: khushi paul ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would depend on how you want to write it (text, line by line or as a blob) and what database you are using.

You'd probably get better answers in the JDBC forum at this point. You have the file stream. That's the main part (for this forum)..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic