• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dowloading a file from a a struts 2 web application

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I wish the users of my webapp to download a file in c:\files space. I have written the following code to use stream result type to let the users download the file. But I get surprising errors. please help me resolve them

When I use


The struts xml fragment is


I still get the following error saying that the name inputStream ( i mean a getter with name inputStream does not exists) It is there in the action class as seen above


I am stuck with this problem for 3 hours and I am not able to solve this. How can struts cannot find whats already in there in its action fragment ??

[edit]Insert line breaks in the code, otherwise it is too wide for my screen. CR[/edit]
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused; you're talking about downloading in the subject and using a stream result, but talking about uploading later.

Yes, you can set where files are uploaded to, either by configuring the underlying upload library, or simply copying the temporary file in the upload action. It doesn't matter where you download the file from, but if it's outside of the web context (or in WEB-INF) you need to stream it to the client yourself.
 
lakshmanan anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, my uploading problem is solved. Where as in download, I get the above mentioned error.. please help
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why wouldn't you just use a normal file input stream?
 
lakshmanan anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Why wouldn't you just use a normal file input stream?



I am beginner to all this. Is this not the right way ? How else can i enable the download service for my struts2 web app. I thought stream result type would be easier ??



And why, inspite of the getter method written there, struts is not seeing it ??
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A stream result *is* the right way to do it--I'm asking why not just use a regular file input stream? It's a hint.
 
lakshmanan anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:A stream result *is* the right way to do it--I'm asking why not just use a regular file input stream? It's a hint.



ya as you said, I have setup the code to




it worked in a wierd manner. the save as window opened at user side but ask the user if it has to download "fileDownload.action" instead of the original file itself. :banghead:
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://struts.apache.org/2.x/docs/stream-result.html
 
lakshmanan anand
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what content types I should give. In my web app users can upload and download any type of file. what content type i should mention in the xml for it to correctly download the file in proper format.

please help
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Here show that You can locat doc information from API

The following is the information from this API, which I think is enough for you.

A custom Result type for sending raw data (via an InputStream) directly to the HttpServletResponse. Very useful for allowing users to download content.

This result type takes the following parameters:

contentType - the stream mime-type as sent to the web browser (default = text/plain).
contentLength - the stream length in bytes (the browser displays a progress bar).
contentDisposition - the content disposition header value for specifing the file name (default = inline, values are typically attachment;filename="document.pdf".
inputName - the name of the InputStream property from the chained action (default = inputStream).
bufferSize - the size of the buffer to copy from input to output (default = 1024).
allowCaching if set to 'false' it will set the headers 'Pragma' and 'Cache-Control' to 'no-cahce', and prevent client from caching the content. (default = true)
contentCharSet if set to a string, ';charset=value' will be added to the content-type header, where value is the string set. If set to an expression, the result of evaluating the expression will be used. If not set, then no charset will be set on the header
These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can provide getContentType() to override that parameter for the current action.

Example:



if you do exactly as this statement, I think the problem will be sovled.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I am able to download file successfully if it is single file. But the issue comes when i try to download multiple files.
I am zipping the files and trying to downaload after creating the zipfile on the server. I would like to download without saving the zipfile on the server. Has anyone tried the same..?
Hope you guys got my question. Any help is appreciated.

Thanks
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only download one file at a time.
 
Kumar Ala
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes David. I am trying to Zip the files and download. But i wanted to send the stream back to Browser rather than storing the Zip file in to the server.
Hope you got the question now.
This i am doing because i can save some time for download file wihtout saving on the server as our client is expected to download big files.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java, as Zip streams aren't Struts-related.
 
reply
    Bookmark Topic Watch Topic
  • New Topic