top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to download file with http post method using spring mvc ?

+1 vote
552 views
How to download file with http post method using spring mvc ?
posted Mar 26, 2018 by Veereshkumar Swamy

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

It should work with the GET (not sure if the POST is even possible),following is the sample code for the get (got it from net) -

@RequestMapping(value = "/exportar/{tipo}", method = RequestMethod.GET)
@ResponseBody
public void exportar(HttpServletResponse response,@PathVariable TipoEnum tipo) throws IOException{

File file = service.exportar(tipo);

response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName() + ".xls"));
        response.setContentType("application/ms-excel; charset=UTF-8"); 
        InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
        FileCopyUtils.copy(inputStream, response.getOutputStream());
    }
answer Mar 27, 2018 by Salil Agrawal
Similar Questions
+1 vote

I have a web application developed using Struts2. In my web application I have a link using which users can download a zip file. I need to create this zip file at run time based on some conditions. How can I do this in Struts2?

+1 vote

enter image description here

This pic is what i am geting error response from server(HTTP 406). Actually i am trying to post some content from CKeditor, but normal text with styles type of content is accepting by server when i add table content server not accepting.

...