• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

convert data in JSP page to .csv format

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic