我需要使用 Jersey Web Services 下载 pdf 文件 我已经执行了以下操作,但收到的文件大小始终为 0(零)。
@Produces({"application/pdf"})
@GET
@Path("/pdfsample")
public Response getPDF() {
File f = new File("D:/Reports/Output/Testing.pdf");
return Response.ok(f, "application/pdf").build();
}
请帮忙做正确的方法,谢谢!!
最佳答案
Mkyong 始终如一。看起来您唯一缺少的是正确的响应 header 。
http://www.mkyong.com/webservices/jax-rs/download-excel-file-from-jax-rs/
@GET
@Path("/get")
@Produces("application/pdf")
public Response getFile() {
File file = new File(FILE_PATH);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition","attachment; filename=test.pdf");
return response.build();
}
关于java - 如何使用 Jersey 下载 PDF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13877081/