commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <rhi...@sympatico.ca>
Subject Re: FileUpload documentation confusing
Date Tue, 01 Jul 2003 16:03:56 GMT
I have included all of the relevant code below; as you can see, my code is
the same as yours and the same as "using" documentation but it doesn't work
due to the ClassCastException on this line:

FileItem item = (FileItem) iter.next();

Any ideas why my code doesn't work? I've run this in the Eclipse Debugger
and the List of items seems just dandy (a group of 4 DefaultFileItems).

-------------------------------------------------------------

/* Check that we have a file upload request. */
boolean isMultipart = FileUpload.isMultipartContent(request);

if (!isMultipart) {

String msg = CLASS_NAME + " - Got a request that was not multipart.";

log(msg);

response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);

return;

}

/* Create a new file upload handler and set some of its attributes. */

DiskFileUpload upload = new DiskFileUpload();

upload.setSizeMax(-1);

upload.setSizeThreshold(1000000);

upload.setRepositoryPath("/");

if (DEBUG) System.out.println("SizeThreshold: " +
upload.getSizeThreshold());

if (DEBUG) System.out.println("SizeMax: " + upload.getSizeMax());

if (DEBUG) System.out.println("RepositoryPath: " +
upload.getRepositoryPath());

/* Parse the request. */

List items;

try {

items = upload.parseRequest(request);

}

catch (FileUploadException fu_excp) {

String msg = CLASS_NAME + " - Error encountered while trying to upload file.
Message: " + fu_excp;

log(msg);

response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);

return;

}

/* Process the uploaded items. */

   Iterator iter = items.iterator();

   while (iter.hasNext()) {

       FileItem item = (FileItem) iter.next();

    // DefaultFileItem item = (DefaultFileItem) iter.next();

      if (item.isFormField()) {

           processFormField(item);

           }

     else {

          processUploadedFile(item);

          }

     } //end while




----------------------------------------------------------------------------
----------------------------------------------

Rhino





----- Original Message ----- 
From: "Bill Comer" <bill.comer@lammtara.com>
To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
Sent: Tuesday, July 01, 2003 11:37 AM
Subject: RE: FileUpload documentation confusing


> Rhino,
>   How did you set up iter ?
>
> The following works for me...
>
> Iterator fileHandler = fileItems.iterator();
>             while ( fileHandler.hasNext() )
>             {
>                     FileItem fi = (FileItem)fileHandler.next();
> .......
>             }
>
> Bill
>
> -----Original Message-----
> From: Rhino [mailto:rhino1@sympatico.ca]
> Sent: 01 July 2003 16:29
> To: Jakarta Commons Users List
> Subject: Re: FileUpload documentation confusing
>
>
> Thanks, I already figured that part out ;-)
>
> Can you tell me what I need to do to get the loop working? I get a
> ClassCastException when I execute the line:
>
> FileItem item = (FileItem) iter.next();
>
> I watched it in the Eclipse debugger and saw that the items in the
> iterator were DefaultFileItems so I changed the above line to say:
>
> DefaultFileItem item = (DefaultFileItem) iter.next();
>
> but this also gave me a ClassCastException. What can I do to resolve
> this problem?
>
> Rhino
>
> ----- Original Message ----- 
> From: "Will Stranathan" <wstranathan@hotmail.com>
> To: <commons-user@jakarta.apache.org>
> Sent: Tuesday, July 01, 2003 10:50 AM
> Subject: Re: FileUpload documentation confusing
>
>
> > A patch was submitted yesterday to update the documentation.  That
> > should
> > be:
> >
> > DiskFileUpload upload = new DiskFileUpload();
> >
> > Regards,
> > Will
> >
> >
> > >From: "Rhino" <rhino1@sympatico.ca>
> > >Reply-To: "Jakarta Commons Users List"
> > ><commons-user@jakarta.apache.org>
> > >To: "commons-user" <commons-user@jakarta.apache.org>
> > >Subject: FileUpload documentation confusing
> > >Date: Tue, 1 Jul 2003 08:30:57 -0400
> > >
> > >I'm trying to use FileUpload 1.0 for the first time but I'm finding
> > >the documentation confusing. I'm referring to the "Using" document at
>
> > >http://jakarta.apache.org/commons/fileupload/using.html.
> > >
> > >According to this document, the first line I need after verifying
> > >that
> the
> > >input is multipart is:
> > >
> > >FileUpload upload = new DiskFileUpload();
> > >
> >
> > _________________________________________________________________
> > The new MSN 8: smart spam protection and 2 months FREE*
> > http://join.msn.com/?page=features/junkmail
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
>
>
>
> ---------------------------------------------------------------------
> 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