Reputation: 59
When I run my war file on Tomcat server then I run my project on chrome and download the xls file from my project and this file showing in tomcat bin folder as well as download folder in our computer.
Please suggest me how we can stop this download file in tomcat bin folder
thanks
String FILE_EXTENSION = ".xlsx";
DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
filename = "SearchPayment_Transactions_" + df.format(new Date()) + FILE_EXTENSION;
File file = new File(filename);
// this Writes the workbook
FileOutputStream out = new FileOutputStream(file);
wb.write(out);
out.flush();
out.close();
wb.dispose();
fileInputStream = new FileInputStream(file);
addActionMessage(filename + " written successfully on disk.");
Upvotes: 0
Views: 642
Reputation: 16185
The file appears twice on your computer, because your servlet code saves the *.xlsx
file to disk before sending it to your browser. That's the behavior your chose in your code.
Remark however, that file
in your code is a relative path, so the folder you write it is the working directory (according to the OS) of your server. The value of the working directory is not defined in the Servlet Specification and may vary from system to system.
A better solution would be:
ServletResponse#getOutputStream()
,(File) servletContext.getAttribute(ServletContext.TEMPDIR)
. E.g. you can replace your file
variable with:final File file = new File((File) servletContext.getAttribute(ServletContext.TEMPDIR), filename);
Upvotes: 0
Reputation: 101
i think the this problem can be sovled, just by fixing the place you want to created the file
String FILE_EXTENSION = ".xlsx"; DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss"); filename = "SearchPayment_Transactions_" + df.format(new Date()) + FILE_EXTENSION; File file = new File(path any fixed directory like temp\filename);
As long as you specify the path where you want to generate the file then it will generating only in tht directory. PLease make proper permission is given to path to generate file, and this will solve your issue.
Upvotes: 1