0

我有一个请求处理程序,它返回内容类型为“application/vnd.ms-excel”id 的 jsp 页面。

我有另一个控制器,我使用 HttpClient 调用了上面的控制器,但我无法下载文件

代码如下:

返回具有 excel 作为内容类型的 jsp 文件的控制器

@RequestMapping(value = {"InvoiceGeneration/generatePDF"}, method=RequestMethod.GET)
                public String generatePDF(Model model)
                {

                }

使用 Http Client 调用上述控制器的控制器

  @RequestMapping(value = {"InvoiceGeneration/generateMonthPDF"}, method=RequestMethod.GET)
                    @ResponseBody
                public  HttpEntity generateMonthPDF(Model model){


                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        HttpGet getRequest = new HttpGet("http://localhost:8080/BillingInvoice/InvoiceGeneration/generatePDF?invoiceNumber=10");
                        getRequest.addHeader("Content-Type", "application/vnd.ms-excel");
                        getRequest.addHeader("Content-Disposition","attachment; filename=\""+"kedar.xls"+"\"");

                            HttpResponse response = httpClient.execute(getRequest);

                        return response.getEntity();

                    }

如何获得excel文件下载的响应????提前致谢

4

1 回答 1

0

必须设置以下响应

         response.setContentType("application/octet-stream");
         or 
         response.setContentType("application/vnd.ms-excel");

         response.setHeader("Content-disposition", "inline;filename=" + fileName);
于 2013-04-04T05:28:41.643 回答