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