I have made two method ExcelCreat() which create excel file And ExcelDownload() which download that excel file. Both work separate properly but not in same time. I made a builder.append("<"<a href='/RestSimulator/rest/userReport/download' onclick='javascript:ExcelCreate();'>Download</a>"); problem is that when I click href(Download) then excel is not created show error 500 file not found but we again press that link then file download.it means first time excel does not genetare but second time generate HOW TO CALL ExcelCreat() method first

downloadMethod(){
  ifNotFileExist(){
    createExcellFile();
  }
  // perform actual download
}