Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want DynamoServlet response as csv

 
Dylan Salmon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, If you can please assist me, I have a public class CSROrderReportLookup extends DynamoServlet. Even when I change the response to CSV the string gets printed to the page instead of prompting for a download. The code I am using is as follows:

PrintWriter fileWriter = null;
response.setContentType("application/csv");
response.setHeader("content-disposition", "filename=test.csv");

fileWriter = response.getWriter();
fileWriter.append("Hello");
fileWriter.flush();

I have a working example of another page that extends GenericFormHandler instead of DynamoServlet which creates a download instead of printing to the page. But I would like to do it from DynamoServlet if at all possible. Can you give me an example of what I may need to change to get it to work?

Thanks,

Dylan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked up DynamoServlet and it appears to be a component of the Oracle ATG commerce platform. I've moved this post to a more appropriate location.
 
Paul Clapham
Sheriff
Posts: 21321
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dylan Salmon wrote:Even when I change the response to CSV the string gets printed to the page instead of prompting for a download. The code I am using is as follows:

PrintWriter fileWriter = null;
response.setContentType("application/csv");
response.setHeader("content-disposition", "filename=test.csv");



That's because the browser which you tested on is configured to do that when it gets files with that MIME type. Here's a link to a help page which addresses how to force a download: How To Raise a "File Download" Dialog Box for a Known MIME Type.

And, welcome to the Ranch!
 
Dylan Salmon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response Paul, however changing adding content-disposition: attachment to response.setHeader("content-disposition: attachment", "filename=test.csv"); has not resolved the issue, the string is still printing inline and not as a file download. Do you have any other suggestions?
 
Paul Clapham
Sheriff
Posts: 21321
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct way to produce this header

Content-disposition: attachment; filename=fname.ext


is


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic