Save as csv file

How can i save the returned data in a csv format? Below is my code.

<jsp:useBean id="mydata"/>

<%

String name= mydata.getname();

String age = mydata.getage();

%>

<table cellspacing="5" cellpadding="1" border="1" width="98%">

<tr>

<td width="56%">Item</td>

<td width="44%">Value</td>

</tr>

<tr>

<td width="56%">Name =></td>

<td width="44%">

(

<font color="blue">

<%=name%>

</font>

).</td>

</tr>

<tr>

<td width="56%" height="30">Age =></td>

<td width="44%" height="30">

(

<font color="blue">

<%=age%>

</font>

).</td>

</tr>

</table>

Currently, i am able to display the name and age on the jsp page. I would like to add a save function on the page. How can i do that? Could someone advise please?

[1439 byte] By [cuppajavaa] at [2007-11-27 1:56:10]
# 1
You can create your own csv file using FileWriter or PrintWriterOr you can use tools like javacsv http://sourceforge.net/projects/javacsv/
kimatrixa at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi,will be file be saved on the client or host machine?
cuppajavaa at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...
# 3
As you are loading the data from database and showing in the html form you can store it to the csv file and then send the file to the client machine.The user can save it to the local machine.
jawadhashmia at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...
# 4
Since i am showing it in a html form, i would like to have a link/button that the user can click so that user can save the csv file in their local machine. How can i achieve this functionality?
cuppajavaa at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...
# 5

I did this a long time ago.

On the click call a servlet/jsp which loads the data as the current page was loading and instead of showing/arranging in the html. Write it to the csv file on server and in the servlet's http response give the path to that temporary file or send the file to the http response with the appropriate tags so instead of displaying the csv in browser the end user can download/save on his machine.

Storing in the file is not a difficult job only you have to think for sending to the client.

Also you can parallel write to csv file and give its link on the page showing the values so the user can instantly download it.

There are limited users who want to download in csv format so doing the two tasks for each request is not a good idea, generate the csv on users request.

Also you can check there is a temp file option while storing the csv file on server side so the server's memory don'r grabbed remove the file as the user's session lost.

jawadhashmia at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...
# 6

Since i am showing it in a html form, i would like to have a link/button that the user can click so that user can save the csv file in their local machine. How can i achieve this functionality?

i will probably be using the suggestion above to use the filewriter to prep the file in csv format. how can i let the user to download it?

cuppajavaa at 2007-7-12 1:30:10 > top of Java-index,Java Essentials,Java Programming...