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

M

Madni

Hi.

while i am trying to respond my client with the dilaog using which a
client user could save the file , the file which is to be sent from
server .... i am facing some issues in
setContentType("Application/csv") .... (file type is csv) ... here is
the chunk of code ....

System.out.println("This line gets displayed before setting content
type");
httpservletresponse.setContentType("application/csv");
System.out.println("After setting content type") // This line 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();

Any suggestion regarding the issue will be highly obliged ...

Regards,
Madni
 
C

Chris Smith

Madni said:
while i am trying to respond my client with the dilaog using which a
client user could save the file , the file which is to be sent from
server .... i am facing some issues in
setContentType("Application/csv") .... (file type is csv) ... here is
the chunk of code ....

System.out.println("This line gets displayed before setting content
type");
httpservletresponse.setContentType("application/csv");
System.out.println("After setting content type") // This line never
gets displayed

Sounds like you've committed the response already. What happens to any
exceptions thrown from setContentType? If there are any, what are they?
If you're swallowing them silently, what are they after you stop
swallowing them? What are you doing to the response before this line?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

josh.s17

This is only a lunch but I think your problem might because you are
using a printwriter to send the response.

Try using an output stream instead eg

OutputStream out = httpservletresponse.getOutputStream;
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top