commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maxime" <max....@free.fr>
Subject [FileUpload] It's works under Firefox but not on IE, why ?
Date Thu, 07 Jul 2005 08:19:20 GMT
Hello Everybody,
During 2 days, I was testing FileUpload on IE and it never work. After =
that, I tried on Firefox and it's works perfectly.
Can you tell me why and how to resolve this problem ?
It's a really pain in an ... :)

Thank you.
Maxime



Here the form :
<HTML>=20
<HEAD>=20
</HEAD>=20

<BODY BGCOLOR=3D"#FDF5E6">=20

<h1>Upload de Fichier</h1>=20

<form name=3D"upload" method=3D"post" action=3D"/UploadFileServlet" =
enctype=3D"multipart/form-data" >=20

Upload File:<input type=3D"file" name=3D"source" size=3D"30">=20
         =20
<input type=3D"submit" name=3D"submitFile" value=3D"Upload" =
title=3D"Upload">=20

</form>=20
</BODY>=20
</HTML>=20

Here the Servlet :

import java.io.*;=20
import java.util.*;=20
import javax.servlet.*;=20
import javax.servlet.http.*;=20
import org.apache.commons.fileupload.*;=20
import org.apache.commons.fileupload.*;=20


public class UploadFileServlet extends HttpServlet {=20
public void doPost(HttpServletRequest request, HttpServletResponse =
response)=20
throws ServletException, IOException {=20

System.out.println ("Uploading-Servlet");=20
        try{       =20
               // Create a new file upload handler=20
               DiskFileUpload upload =3D new DiskFileUpload();=20
               =20
               // Set upload parameters=20
               int  yourMaxMemorySize =3D 512 * 1024 * 8;=20
               int  yourMaxRequestSize =3D 1024 * 1024 * 8;=20
               String yourTempDirectory =3D "c:\\";=20
               =20
               upload.setSizeThreshold(yourMaxMemorySize);=20
               upload.setSizeMax(yourMaxRequestSize);=20
               upload.setRepositoryPath(yourTempDirectory);=20

               //Parse the request=20
               List items =3D upload.parseRequest(request);=20
               =20
               // Process the uploaded items=20
               Iterator iter =3D items.iterator();=20
               while (iter.hasNext()) {=20
                   =20
                   FileItem item =3D (FileItem) iter.next();=20
                   =20
                   //   Process a regular form field=20
                   if (item.isFormField()) {=20
                       String name =3D item.getFieldName();=20
                       String value =3D item.getString();=20
                       =20
                   }=20
                  // Process a file upload=20
                  else {=20
                       String fieldName =3D item.getFieldName();=20
                       String fileName =3D item.getName();=20
                       String contentType =3D item.getContentType();=20
                       boolean isInMemory =3D item.isInMemory();=20
                       File uploadedFile =3D new File(yourTempDirectory =
+ fileName);=20
                       item.write(uploadedFile);=20

                  }=20
               }=20
            } catch (ServletException e) {=20
               e.printStackTrace();=20
            } catch (IOException e) {=20
               e.printStackTrace();=20
            } catch (FileUploadException e) {=20
               e.printStackTrace();=20
            } catch (Exception e) {=20
               e.printStackTrace();=20
            }=20

   }=20
   =20
} 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message