• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to download dynamic data in struts

 
Anjali Pal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anjali Pal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic