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]

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.
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?