This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!

ram shakthi

Greenhorn
+ Follow
since Apr 02, 2017
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ram shakthi

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);

}