aspose file tools*
The moose likes Other Java Products and Servers and the fly likes Want DynamoServlet response as csv Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Want DynamoServlet response as csv" Watch "Want DynamoServlet response as csv" New topic
Author

Want DynamoServlet response as csv

Dylan Salmon
Greenhorn

Joined: Nov 30, 2012
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61064
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 30, 2012
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The correct way to produce this header

Content-disposition: attachment; filename=fname.ext


is


 
jQuery in Action, 2nd edition
 
subject: Want DynamoServlet response as csv