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