I am working on a JAVA EXTJS application in which I need to create and upload a CSV file.
When I click the button, I want the CSV file to be downloaded to the client machine.
In button listening mode, I invoke the servlet using ajax. There I create a CSV file.
I do not want the CSV file to be saved on the server. I want the file to be created dynamically with the ability to download.
I want the contents of the file to be created as a string, and then I will serve the content as a file, in which it will be displayed as the download mode in the browser. (This I achieved in another language, but not sure how to achieve it in java)
Here is my code only for creating a CSV file, but I really don't want to create or save a CSV file if I can only download the file as a CSV.
public String createCSV() { try { String filename = "c:\\test.csv"; FileWriter fw = new FileWriter(filename); fw.append("XXXX"); fw.append(','); fw.append("YYYY"); fw.append(','); fw.append("ZZZZ"); fw.append(','); fw.append("AAAA"); fw.append(','); fw.append("BBBB"); fw.append('\n'); CSVResult.close(); return "Csv file Successfully created"; } catch(Exception e) { return e.toString(); } }
Can anyone help me on this.
thanks
java csv extjs4
Gourav
source share