You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tom Holmes Jr." <to...@tomholmes.net> on 2008/03/27 15:28:07 UTC

FormFile to Next Page

I have found dozens of examples on the Net to use Struts 1 to upload a 
file using the FormFile object.
This works great.   However, there is probably a bug in the FormFile 
since getting the inputStream doesn't seem to work.
But using the getFileData to get the byte array does work fine, so then 
I have to create a ByteArrayInputStream.

Anyway, my question is after I upload my file and look at the data, I 
want to hold onto that file to the next page.
Can I do that.   After I successfully upload my CSV file on the first 
page, and parse it to get the first line which are headers.
Then I go to the next JSP page and I display those headers ... and I 
want to keep that FormFile around from the first page.

Can I do this, or do I need to parse the entire file after the first 
page, and then how would I persist this without writing it to a database.

Thanks!
                         Tom


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


Re: FormFile to Next Page

Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>
> Yes, I thought I mentioned that .... I could parse it and store it until
> I need it.
> However, I don't like to store data like that in a session ... it could
> be a lot of data.
> But I could pass it into the request ....



Wait a moment, maybe I misunderstood.
You are writing about "pages", but do they stay in the same HTTP request?
If yes, ok, the FormFile is available through the whole request, but it can
be read only once (IIRC).

Antonio

Re: FormFile to Next Page

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
Yes, I thought I mentioned that .... I could parse it and store it until 
I need it.
However, I don't like to store data like that in a session ... it could 
be a lot of data.
But I could pass it into the request ....

Antonio Petrelli wrote:
> 2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>   
>> Well, my use case, I am parsing a CSV file and the first line contains
>> the header information.
>> Each column has a header .... so rather than parse the entire file at
>> this time, I just grab the first line.
>> That's all I need to do in that action, then I need to hold onto that
>> file, and then go to the next page.
>> I need some user/mapping information on this second page ... and then
>> when I submit from the second page.
>> Then I have all the information I need so I can parse the rest of the
>> data.
>>
>> If I parse the file after the first page ... I'm not ready to do
>> anything with it yet.
>> So, I still need to hold onto this file until after the second page.
>> That's my use case.      Thanks!
>>     
>
>
>
> Why don't you parse it "before" you need it, storing the result of the
> parsing in session?
>
> Antonio
>
>   
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 7.5.519 / Virus Database: 269.22.1/1346 - Release Date: 3/27/2008 10:03 AM
>   


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


Re: FormFile to Next Page

Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>
> Well, my use case, I am parsing a CSV file and the first line contains
> the header information.
> Each column has a header .... so rather than parse the entire file at
> this time, I just grab the first line.
> That's all I need to do in that action, then I need to hold onto that
> file, and then go to the next page.
> I need some user/mapping information on this second page ... and then
> when I submit from the second page.
> Then I have all the information I need so I can parse the rest of the
> data.
>
> If I parse the file after the first page ... I'm not ready to do
> anything with it yet.
> So, I still need to hold onto this file until after the second page.
> That's my use case.      Thanks!



Why don't you parse it "before" you need it, storing the result of the
parsing in session?

Antonio

Re: FormFile to Next Page

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
Well, my use case, I am parsing a CSV file and the first line contains 
the header information.
Each column has a header .... so rather than parse the entire file at 
this time, I just grab the first line.
That's all I need to do in that action, then I need to hold onto that 
file, and then go to the next page.
I need some user/mapping information on this second page ... and then 
when I submit from the second page.
Then I have all the information I need so I can parse the rest of the data.

If I parse the file after the first page ... I'm not ready to do 
anything with it yet.
So, I still need to hold onto this file until after the second page.
That's my use case.      Thanks!
                                                                     Tom

Antonio Petrelli wrote:
> 2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>   
>> Ok ..... maybe what I'll do in this case is put the FormFile into the
>> request manually
>>     
>
>
>
> Isn't it easier to parse the FormFile in the action?
>
> Antonio
>
>   
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 7.5.519 / Virus Database: 269.22.1/1346 - Release Date: 3/27/2008 10:03 AM
>   


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


Re: FormFile to Next Page

Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>
> Ok ..... maybe what I'll do in this case is put the FormFile into the
> request manually



Isn't it easier to parse the FormFile in the action?

Antonio

Re: FormFile to Next Page

Posted by Laurie Harper <la...@holoweb.net>.
Storing the FormFile reference into the request wont help; request 
attributes are discarded at the end of request processing, so by the 
time the next page submits the first request has gone away. To keep 
something from one request available to the next request, you would have 
to put it into the session.

However, storing a FormFile reference in the session probably wont help 
either. A FormFile is just a chunk of meta data that allows the physical 
file to be found on disk. If the physical file is deleted, having a 
reference to where it used to be isn't very useful...

You will either need to read the whole file in the first request and 
cache the data somewhere (e.g. in the session), or make a copy the file 
to load in the second request. You need to make a copy (of the file, or 
the data in it) as Struts will automatically delete the original file at 
the end of the request in which it was received.

L.

Tom Holmes Jr. wrote:
> Ok ..... maybe what I'll do in this case is put the FormFile into the 
> request manually, so I can pass it from one page to the next.
> I'm not so much concerned with the FormFile.getInputStream since I can 
> use FormFile.getFileData to get the byte array data.
> 
> Thanks!
> 
> Antonio Petrelli wrote:
>> 2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>>  
>>> Anyway, my question is after I upload my file and look at the data, I
>>> want to hold onto that file to the next page.
>>>     
>>
>> ...
>>  
>>> Can I do this, or do I need to parse the entire file after the first
>>> page, and then how would I persist this without writing it to a 
>>> database.
>>>     
>>
>>
>>
>> You need to parse the input stream as it comes. The reason why the 
>> FormFile
>> does not return an input stream at the following request is that the 
>> input
>> stream is connected to the previous HTTP request.
>> How you can persist it is a problem of yours, Struts cannot help in this.
>> But anyway, I suggest to parse that file and "remember" only the portions
>> you really need.
>>
>> Antonio
>>
>>   
>> ------------------------------------------------------------------------
>>
>> No virus found in this incoming message.
>> Checked by AVG. Version: 7.5.519 / Virus Database: 269.22.1/1346 - 
>> Release Date: 3/27/2008 10:03 AM
>>   


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


Re: FormFile to Next Page

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
Ok ..... maybe what I'll do in this case is put the FormFile into the 
request manually, so I can pass it from one page to the next.
I'm not so much concerned with the FormFile.getInputStream since I can 
use FormFile.getFileData to get the byte array data.

Thanks!

Antonio Petrelli wrote:
> 2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>   
>> Anyway, my question is after I upload my file and look at the data, I
>> want to hold onto that file to the next page.
>>     
>
> ...
>   
>> Can I do this, or do I need to parse the entire file after the first
>> page, and then how would I persist this without writing it to a database.
>>     
>
>
>
> You need to parse the input stream as it comes. The reason why the FormFile
> does not return an input stream at the following request is that the input
> stream is connected to the previous HTTP request.
> How you can persist it is a problem of yours, Struts cannot help in this.
> But anyway, I suggest to parse that file and "remember" only the portions
> you really need.
>
> Antonio
>
>   
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG. 
> Version: 7.5.519 / Virus Database: 269.22.1/1346 - Release Date: 3/27/2008 10:03 AM
>   


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


Re: FormFile to Next Page

Posted by Antonio Petrelli <an...@gmail.com>.
2008/3/27, Tom Holmes Jr. <to...@tomholmes.net>:
>
> Anyway, my question is after I upload my file and look at the data, I
> want to hold onto that file to the next page.

...
> Can I do this, or do I need to parse the entire file after the first
> page, and then how would I persist this without writing it to a database.



You need to parse the input stream as it comes. The reason why the FormFile
does not return an input stream at the following request is that the input
stream is connected to the previous HTTP request.
How you can persist it is a problem of yours, Struts cannot help in this.
But anyway, I suggest to parse that file and "remember" only the portions
you really need.

Antonio