java - HttpServletResponse getOutputStream sending html code on csv file -


i'm trying download csv file html code (header , footer) sent file. i'm using weblogic, tomcat works fine. code below:

public void downloadcsvreport(string csvfile, httpservletresponse response){         try {              response.setheader("content-disposition", "attachment; filename=example.csv");              response.setcontenttype("text/csv");              bytearrayinputstream bais = new bytearrayinputstream(csvfile.tostring().getbytes(report_encoding));             ioutils.copy(bais, response.getoutputstream());              response.flushbuffer();          } catch( ioexception e ){             logger.error(e.getmessage(), e);         }     } 

thanks!

this code in spring webapp works

public static void putfileinresponse(httpservletresponse response, file file, string contenttype) throws ioexception {     // set headers     response.setcontenttype(contenttype);// "application/octet-stream" example     response.setcontentlength((int) file.length());     response.addheader("content-disposition", new stringbuilder("attachment; filename=\"").append(file.getname()).append("\"").tostring());     response.addheader("content-description", "file transfer");     response.addheader("content-transfer-encoding", "binary");     response.addheader("expires", "0");     response.addheader("cache-control", "no-cache, must-revalidate");     response.addheader("pragma", "public");     response.addheader("content-transfer-encoding", "binary");      // write content of file in response     try (fileinputstream fis = new fileinputstream(file); outputstream os = response.getoutputstream()) {         ioutils.copylarge(fis, os);         os.flush();     } } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -