aspose file tools*
The moose likes Struts and the fly likes How to download dynamic data in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to download dynamic data in struts" Watch "How to download dynamic data in struts" New topic
Author

How to download dynamic data in struts

Anjali Pal
Greenhorn

Joined: Oct 03, 2009
Posts: 16
HI Experts,

I am working on project in struts and tomcat 6.0 .

I am displaying some data on a jsp and i want that the data i am displaying on the jsp the user should be able to download it as a .txt or .html file. The data is basically a Array list of type String .
This data is coming dynamically from database and changes depending on user selection.

I tried some code from the net but the code returns all my other stuff from jsp like images,javascript etc. Its like looking at my jsp's source code.

I have the the Array List available at my Action Class. And i want that only the contents inside this Array list should only be downloaded .

I am stuck So please guide me through this . I cannot store this file on the server as the content of the file changes on every selection .

Thank you in advance ,

Regards.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

If you want to download that text, then on 'Download' link action, perform following steps:
1. Create a temp file
2. Write all the string into that file.
3. By setting proper header, forward


If you want the user can copy paste the generated text, then use:
<textarea cols="12" rows="3"><jsp:include page="GetTheText.do"/></textarea>
GetTheText is mapped to the action and opens the "out" stream and write the strings, like

PS: I never tried both the example before, so let me know Ranchers whether my appraoch is correct or not


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Anjali Pal
Greenhorn

Joined: Oct 03, 2009
Posts: 16
Hi,

1. Create a temp file
2. Write all the string into that file.


Am just confused about where this temp file should be stored to avoid any problems at the time of deployment.

Right now during development i can store it any where but which is the right and best place to store or create the temp file, to avoid deployment time troubles.



And i tried this code but as i said it returns the entire jsp and not the specific section of it .

Thank you ,

Regards.



Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Anjali Pal wrote:
1. Create a temp file
2. Write all the string into that file.
Am just confused about where this temp file should be stored to avoid any problems at the time of deployment.
Right now during development i can store it any where but which is the right and best place to store or create the temp file, to avoid deployment time troubles.

Do not worry about the temp file creation, it is handled by Java. For more info on creating temp file, Google temp file using Java. You can also create your own dir into the web app named "temp".
Anjali Pal wrote:

And i tried this code but as i said it returns the entire jsp and not the specific section of it .

Entire JSP ?? Have you tried specifying the filename in the header ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to download dynamic data in struts