码迷,mamicode.com
首页 > 编程语言 > 详细

java文件下载 rest

时间:2016-06-13 15:20:14      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:

/**
     * 返回文件二进制
     * 
     */
    @GET
    @Path("/excel")
    @Produces("application/vnd.ms-excel; charset=UTF-8")
    @ModuleSecurityAuth(moduleId=ModuleId.MONITOR_REPORT ,privilegeOperation=PrivilegeOperation.READ)
    public Response download(final @QueryParam("path") String path) throws IOException {
        File file = new File("/macc/excel/"+path);
    //解决文件名乱码

      String pathTmp = java.net.URLEncoder.encode(path, "UTF-8");


         
        ResponseBuilder response = Response.ok((Object) file);
        String header = "attachment; filename=" + pathTmp;
        response.header("Content-Disposition",
                header);
        return response.build();
    }

 

java文件下载 rest

标签:

原文地址:http://www.cnblogs.com/guochunyi/p/5580561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!