commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tatu Vanhanen" <tatu.vanha...@graftor.fi>
Subject RE: fileupload newbie question
Date Tue, 06 Jul 2004 05:20:44 GMT
The request's inputstream (or reader) can be consumed only once. So because you have already
used it, there's not much left for the DiskFileUpload. Try parsing the request with FileUpload
without the code that outputs the request to System.out.

- Tatu V.

> -----Original Message-----
> From: Qingtian Wang [mailto:Qingtian.Wang@ualloyalty.com]
> Sent: 6. heinäkuuta 2004 3:10
> To: commons-user@jakarta.apache.org
> Subject: fileupload newbie question
> 
> 
> Hi,
> 
> I've got this form in my JSP:
> 
>         <DEFANGED_form action='/telescope/prototype/readExcel' 
> enctype='multipart/form-data' method='post'>
>         <table>
>             <tr><td>form field:</td><td><input type='text'

> size='10' name='formFieldName'/></td></tr>
>             <tr><td>Excel file to upload:</td><td><DEFANGED_input

> type='file' /></td></tr>
>             <tr><td><DEFANGED_input type='submit' /></td></tr>
>         </table>
>         </DEFANGED_form>
> 
> 
> In the processing servlet, I have:
> 
> ~~~~~~~ Servlet ~~~~~~~
> <DEFANGED_snip>
> 
>             InputStream is = request.getInputStream();
>             InputStreamReader isReader = new InputStreamReader(is);
>             BufferedReader bReader = new BufferedReader(isReader);
>             String sOut = "";
> 
>             while ((sOut = bReader.readLine()) != null) {
>                 System.out.println(sOut);
>             }
> 
> 		List fileItems = new DiskFileUpload().parseRequest(request);
> 		System.out.println("Number of file items -- " + 
> fileItems.size());
> 
> <DEFANGED_snip>
> ~~~~~~~
> 
> With that servlet, I always get "0" printed out as the size of 
> the fileItems while I did enter the first text field and the 
> second file to upload. And if I print out the HttpServletRequest 
> "request" out of its InputStream, it does show the first text 
> field, both name and the value I entered; but for the second file 
> upload, it only shows an id-like line that looks like this:
> 
> ~~~~~~~ output ~~~~~~~
> <DEFANGED_snip>
> 
> -----------------------------20053262110829
> Content-Disposition: form-data; name="formFieldName"
> 
> my value
> -----------------------------20053262110829--
> Number of file items -- 0
> 
> <DEFANGED_snip>
> 
> ~~~~~~~
> 
> What puzzles me here is that even if the second input, which the 
> file upload part, didn't work out, the size of the "fileItems" 
> still shouldn't be "0" because the request input stream clearly 
> show that the first input, which is the text form-field input, is 
> being successfully passed to the servlet. In that case, the 
> parseRequest() method should at least return 1 item in the list 
> of FileItems.
> 
> Any ideas?
> 
> Thanks very much for your help!
> Qingtian Wang
> 
> 


---------------------------------------------------------------------
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