Search code examples
javaexceljspjsfjsf-2

Is it possible to create a link in a JSP or JSF page to a dynamically generated file that is stored in HttpSession object


I have an upload form that submits an Excel file to a Spring Framework backend program. The backend program parses the Excel file using the Apache POI framework and stores the row and column data in the database.

What I would like to do is in case there are errors, i would like to mark the offending cell in bold red font and modify the originally uploaded excel file and store it in the HttpSession. I would then like to create a Download link to the modified excel file in the session so that the user can examine the excel file a correct the erroneous data (those marked in bold red font).

Is it possible to create the download link in JSF or JSP to the Excel file stored in the HttpSession. If yes, how would the link be scripted in JSF or JSP.

I have no problem manipulating the uploaded excel file using POI. I need help only in crafting the download link on the JSF or JSP page.

Thanks in advance. Any help and suggestions will be highly appreciated.


Solution

  • create a Link in jsp ....call the below code..make sure you have all the records in excel

        file = new File(device_records.xlsx);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=device_records.xlsx");
        out = new FileOutputStream(file);
        workbook.write(out);
        workbook.write(response.getOutputStream());