vendredi 10 avril 2015

How to force download file with Spring controller?

i have a string controller to download a xml file but the download window is open everytime..


this is the code of my controller :



@RequestMapping(value = "/export", method = RequestMethod.POST)
@ResponseBody
public void export(HttpServletRequest request, HttpServletResponse response) throws JsonGenerationException,
JsonMappingException, IOException, DatatypeConfigurationException {
byte[] bytes = service.exportXML(getUsername());
String xmlFileName = "filename.xml";
response.setContentType("application/force-download");
response.setHeader("Content-Length", String.valueOf(bytes.length));
response.setHeader("Content-Disposition", "attachment; filename="+xmlFileName);

response.getOutputStream().write(bytes);
}


What i can do to browser never open download window and save the file immediately?


Aucun commentaire:

Enregistrer un commentaire