如何指示从Jersey的REST服务保存到浏览器的文件名? [英] How to indicate the file name for saving to the browser from a REST service in Jersey?

查看:55
本文介绍了如何指示从Jersey的REST服务保存到浏览器的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让REST服务从本地硬盘驱动器返回一个zip文件. 以下是我在做什么,

i am trying to have a REST service return a zip file from the local harddrive . Following is what i am doing ,

@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();

    }
}

现在,当我使用浏览器时. Internet Explorer并键入URL http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345 我看到一个文件下载对话框,上面写着您是否要保存文件l345`.

Now when i use the browser ie. Internet Explorer and key in the url http://localhost:9788/mockRESTServer/rest/interface3/123456/k123/l345 i see a file download dialog that says "Do you want to save the file l345`.

我希望它向我索要zip下载,即. D:\\Documentation\\Documentation.zip. 但是以某种方式占用了请求URL中的最后一个参数.

i want it to ask me for the zip download ie. D:\\Documentation\\Documentation.zip. But somehow it takes up the last parameter in the request URL.

推荐答案

return Response.ok(f, mt)
        .header("Content-Disposition", "attachment; filename=Documentation.zip")
        .build();

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆