commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Collin <coll...@laboiteaprog.com>
Subject upload file
Date Fri, 10 Mar 2006 19:34:48 GMT
hi

i try to send only a file with fileupload and save the file to the server

my jsp file
<form action="Upload" method="POST" enctypetype="multipart/form-data"> 
  <input type="file" name="file">
  <input type="SUBMIT" name="button" value="Envoie">
</form>

my servlet

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);	

try{
  List items = upload.parseRequest(request);
  Iterator iter = items.iterator();
  if (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    System.out.println(item.getName());				
    File uploadedFile = new File(item.getName());
    try{
      item.write(uploadedFile);
     }catch (Exception e) {
	e.printStackTrace();
     }		
   } 
}catch (FileUploadException e) {
  e.printStackTrace();
}

is it the correct way to upload and file file?

why i try to upload i file i get:

javax.servlet.ServletException: error cannot instantiate servlet Upload class

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
        
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
        
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
        
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
        java.lang.Thread.run(Thread.java:534)


java.lang.NoClassDefFoundError: 
org/apache/commons/fileupload/FileUploadException
        java.lang.Class.getDeclaredConstructors0(Native Method)
        java.lang.Class.privateGetDeclaredConstructors(Class.java:1618)
        java.lang.Class.getConstructor0(Class.java:1930)
        java.lang.Class.newInstance0(Class.java:278)
        java.lang.Class.newInstance(Class.java:261)
        
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
        
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
        
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
        
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
        java.lang.Thread.run(Thread.java:534)


thanks
-- 
www.laboiteaprog.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message