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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM