i cant download my excel file in netbeans
this type of error comes...please help me to solve this
"Excel cannot open the file "workbook.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted
and that the file extension matches the format of the file"
this is my codeing
<%@page import="java.io.FileInputStream"%>
<%@ page contentType="application/vnd.ms-excel" pageEncoding="ISO-8859-1"%>
<%response.setHeader("Content-Disposition", "attachment;filename=paxsearchlist.xlsx"); %>
<%
try
{
String fil=request.getParameter("fname");
System.out.println(fil);
// ServletContext context = getServletContext();
//
String dirName =context.getRealPath("/staffs/");
// System.out.println(dirName);
//
String filepath=dirName;
//
System.out.println(filepath);
//response.setContentType("text/html");
//FileInputStream fileInputStream = new FileInputStream(filepath +"/"+ fil);
//System.out.println(fileInputStream);
//int i;
//while((i=fileInputStream.read())!=-1)
//
{
// System.out.println(i);
//out.write(i);
//
}
//.close();//
out.close();
ServletContext context = getServletContext();
String path=context.getRealPath("\\.xlsx\\");
//String filepath = "e:\\";
response.setContentType("/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition","attachment; filename=\"" + fil + "\"");
java.io.FileInputStream fileInputStream = new java.io.FileInputStream(path +"\\"+ fil);
int i;
while ((i=fileInputStream.read()) != -1)
{
out.write(i);
}
fileInputStream.close();
} catch (Exception e)
{
System.out.println(e);
}