problem faced while using setContentType("Application/csv")

M

Madni

Hi .

I am trying to send csv file from server to client , i can see the
dialog which can be used to save the file on the specific location on
the client side ... but no information is sent and file is saved with 0
bytes ... can any one please guide me in this ...

Here is the chunk of code using which i am trying to send csv ...
System.out.println("before setting contenttype "); // this statement
always gets printed
httpservletresponse.setContentType( "application/csv");
System.out.println("after setting contenttype ");// this statement
never gets displayed
httpservletresponse.setHeader("Content-Disposition","inline;
filename=" +strtemp[1]+".csv" );

try {
File uFile = new File(strFilePath);
int fSize = (int) uFile.length();
FileInputStream fis = new
FileInputStream(uFile);
PrintWriter pw =
httpservletresponse.getWriter();
int c = -1;
while ( (c = fis.read()) != -1) {
pw.print( (char) c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw = null;
}
catch (Exception e) {
System.out.println("Exception is caught
");
e.printStackTrace();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top