java - Spring MVC Sending Apache POI file to client browser from controller -
i'm attempting pass excel file have created apache poi client browser, triggers download on browser. i'm aware common issue, cannot seem figure out quite doing wrong in scenario. must small or logically incorrect.
@restcontroller @requestmapping("/admin/home") @api(tags = {"site_endpoint"}) @responsebody public class filedownloadcontroller { private httpservletresponse servletresponse; @autowired public filedownloadcontroller(final httpservletresponse servletresponse) { this.servletresponse = servletresponse; } @requestmapping(value = "download/downloadpage/{param1}/pagenum/{param2}", method = requestmethod.get) public map<string, string> getbyasmsandcountrycode( @pathvariable final string param1, @pathvariable final string param2, httpservletresponse response){ // initialize worksheet here.. final workbook workbook = new hssfworkbook(); //add sheets worksheet here ..// servletresponse.setcontenttype("application/x-ms-excel"); // set mime type servletresponse.addheader("content-disposition", "attachment; filename=" + filename); try ( outputstream out = servletresponse.getoutputstream()) { workbook.write(out); servletresponse.getwriter(); out.flush(); out.close(); this.response.put(feedback, "file downloaded."); logger.info("successful download " + filename); } catch (final ioexception e) { this.response.put(feedback, "an io error occurred"); logger.info("io error occurred", e); } catch (final exception e) { this.response.put(feedback, e.tostring()); logger.info("other error"); } return this.response; }
in current state, download of file not triggered on browser. correctley using outputstream , servlet response trigger this?
all appreciated!
Comments
Post a Comment