我正在尝试向最终用户提出将服务器响应作为excel文件进行下载的请求。但是我无法显示excel或word的下载对话框,而我能够使用相同的代码进行pdf和pdf文件正在下载。我做错了什么。
这是我的代码:
@GET
@Path("/getDislikeData")
@Produces("application/vnd.ms-excel")
public Response getDislikeData() throws FileNotFoundException{
ToExcel te= new ToExcel();
te.createExcel();
File file = new File("C:\\XLS\\offers.xls");
ResponseBuilder response = Response.ok((Object) file);
response.header("content-disposition","attachment;filename=offers.xls");
return response.build();
}
我尝试过的东西是@Produces(“application / vnd.ms-excel”)和@Produces(“application / vnd.openxmlformats-officedocument.spreadsheetml.sheet”)。
我也试过@Produces(“application / msword”)并尝试下载word文件而不是Excel,但它也没有帮助。
它只显示乱语。
答案 0 :(得分:0)
问题解决了。实际上这不是编码问题,而是浏览器问题。浏览器在屏幕上显示文件,而不是提供打开/保存提示。