• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert data in JSP page to .csv format

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jsp page, where data comes in from a database. I want to convert this data into .csv format.

I have written the following lines of code in the onClick event of the button:

response.setContentType("text/csv");
response.setHeader("Content-Disposition","filename=\"test.csv\"");

This code is inside scriptlet tags inside the javascript function.

I find that in addition to the data, all the javascript function etc. appear in the .csv file. Also, i want the file open dialog box to open, when i click on a button. But, now this is happening on page load.

How to rectify this?

***************************************************************************
I also tried the following approach:

I have a jsp page with a button, the javascript onClick() for this button is:

if(flag=="CSV"){
var fileName = "/eriapps/frameset.do?action=CsvErricsson";
var win1 = window.open(fileName,"_blank",'resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no');
}

fileName points to a servlet, SO the servlet class has the following code:

theResponse.setContentType("text/csv");
theResponse.setHeader("Content-Disposition","filename=\"test.csv\"");

This code compiles, doesnt throw any errors, but doesnt serve the purpose. It doesnt write the o/p to a .csv file.Doesnt even open the file dialog box...

please help!
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriplets will not work within javascript function.
You need also open some stream with CSV data written in it. It will not happen automaticaly just by setting content type.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!