java文件下载 rest

/**
     * 返回文件二进制
     * 
     */
    @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();
    }

 

posted @ 2016-06-13 14:39  無限大  阅读(2084)  评论(0编辑  收藏  举报