Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何指示要从Jersey的REST服务保存到浏览器的文件名?_Java_Rest_Jersey_Jax Rs - Fatal编程技术网

Java 如何指示要从Jersey的REST服务保存到浏览器的文件名?

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

我正在尝试让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  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并输入url
http://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中最后一个
/
之后的名称,这是非常合理的。