Java 如何指示要从Jersey的REST服务保存到浏览器的文件名?
我正在尝试让REST服务从本地硬盘返回zip文件。 下面是我正在做的事情Java 如何指示要从Jersey的REST服务保存到浏览器的文件名?,java,rest,jersey,jax-rs,Java,Rest,Jersey,Jax Rs,我正在尝试让REST服务从本地硬盘返回zip文件。 下面是我正在做的事情 @Path("/interface3/{Ent_id}/{esf_app_id}/{esf_app_ver}") public class Interface3Mock { // This method is called if TEXT_PLAIN is request @GET @Produces("application/zip") public Response callInte
@Path("/interface3/{Ent_id}/{esf_app_id}/{esf_app_ver}")
public class Interface3Mock {
// This method is called if TEXT_PLAIN is request
@GET
@Produces("application/zip")
public Response callInterface3_text(
@PathParam("Ent_id") Integer entitlement_id,
@PathParam("eapp_id") String eapp_id,
@PathParam("eapp_ver") String eapp_ver) {
File f = new File("D:\\Documentation\\Documentation.zip");
String mt = new MimetypesFileTypeMap().getContentType(f);
return Response.ok(f, mt).build();
}
}
现在,当我使用浏览器ie.Internet Explorer并输入urlhttp://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345
我看到一个文件下载对话框,上面写着“是否保存l345文件”
我想让它向我索取zip下载,即。D:\\Documentation\\Documentation.zip
。
但不知何故,它占用了请求URL中的最后一个参数
return Response.ok(f, mt)
.header("Content-Disposition", "attachment; filename=Documentation.zip")
.build();
请参见您能解释一下为什么会出错吗?这将对我学习这方面有很大帮助。:)IE使用URL确定默认文件名,以提示用户保存文档,就像此标题不存在一样,如果您没有明确指定要使用的文件名(这通常通过标准完成)然后它进行猜测。显然,它猜测文件名是URL中最后一个
/
之后的名称,这是非常合理的。