problem faced while using setContentType("Application/csv")  
Author Message
Madni





PostPosted: 2006-1-2 20:17:00 Top

java-programmer, problem faced while using setContentType("Application/csv") 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

 
Madni





PostPosted: 2006-1-2 21:02:00 Top

java-programmer >> problem faced while using setContentType("Application/csv") 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();
}

 
Chris Smith





PostPosted: 2006-1-4 12:26:00 Top

java-programmer >> problem faced while using setContentType("Application/csv") Madni <email***@***.com> wrote:
> 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
 
 
josh.s17





PostPosted: 2006-1-4 18:35:00 Top

java-programmer >> problem faced while using setContentType("Application/csv") 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;