You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark <el...@gmail.com> on 2005/07/25 15:54:55 UTC

Internet Explorer and Content-Type

I have a servlet that generates data that I want to write to the
client's browser.  This data is just ASCII text.  The problem that I
am running into is that Internet Explorer's "Save As" window defaults
the filename to the name of my servlet.  Firefox/Netscape will save
the file as the filename that I specify in the Content-Type HTTP
header.
Does anyone know how to fix this?

Here is the code that I am currently using:

response.setContentType("text/xyz" );
response.setHeader("Content-Disposition", "Attachment; filename=\"blah.xyz\"");

Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Internet Explorer and Content-Type

Posted by Mark <el...@gmail.com>.
Could it be that I am writing a text file, where you are writing a zip file ?

On 7/25/05, Arup Vidyerthy <li...@yahoo.co.uk> wrote:
> Strange... I have identical code and it works IE and FireFox.
> 
> This is how write it out into the response stream
> 
> // set up the response header with the content type, the file name and
> // the file size
> //
> res.setContentType("application/zip");
> res.setHeader("Content-disposition", "attachment; filename=" +
> file.getName());
> res.setHeader("Content-Length", String.valueOf(file.length()));
> 
> // create a URL object for the tmp file, create the input stream from
> // the URL
> //
> URL url = getServletContext().getResource(filename);
> input = new BufferedInputStream(url.openStream());
> 
> // read from the file, write to the servlet output stream
> //
> byte[] buff = new byte[1024];
> int bytesRead;
> while (-1 != (bytesRead = input.read(buff, 0, buff.length))) {
>         output.write(buff, 0, bytesRead);
> }
> 
> 
> The only difference I can see is how I use lowercase but I don't see why
> that should make any difference.
> 
> 
> 
> -----Original Message-----
> From: Mark [mailto:elihusmails@gmail.com]
> Sent: 25 July 2005 14:55
> To: Tomcat Users List; elihusmails@gmail.com
> Subject: Internet Explorer and Content-Type
> 
> I have a servlet that generates data that I want to write to the client's
> browser.  This data is just ASCII text.  The problem that I am running into
> is that Internet Explorer's "Save As" window defaults the filename to the
> name of my servlet.  Firefox/Netscape will save the file as the filename
> that I specify in the Content-Type HTTP header.
> Does anyone know how to fix this?
> 
> Here is the code that I am currently using:
> 
> response.setContentType("text/xyz" );
> response.setHeader("Content-Disposition", "Attachment;
> filename=\"blah.xyz\"");
> 
> Thank you.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> ___________________________________________________________
> Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Internet Explorer and Content-Type

Posted by Arup Vidyerthy <li...@yahoo.co.uk>.
Strange... I have identical code and it works IE and FireFox.

This is how write it out into the response stream

// set up the response header with the content type, the file name and
// the file size
//
res.setContentType("application/zip");
res.setHeader("Content-disposition", "attachment; filename=" +
file.getName());
res.setHeader("Content-Length", String.valueOf(file.length()));

// create a URL object for the tmp file, create the input stream from
// the URL
//
URL url = getServletContext().getResource(filename);
input = new BufferedInputStream(url.openStream());

// read from the file, write to the servlet output stream
//
byte[] buff = new byte[1024];
int bytesRead;
while (-1 != (bytesRead = input.read(buff, 0, buff.length))) {
	output.write(buff, 0, bytesRead);
} 


The only difference I can see is how I use lowercase but I don't see why
that should make any difference.



-----Original Message-----
From: Mark [mailto:elihusmails@gmail.com] 
Sent: 25 July 2005 14:55
To: Tomcat Users List; elihusmails@gmail.com
Subject: Internet Explorer and Content-Type

I have a servlet that generates data that I want to write to the client's
browser.  This data is just ASCII text.  The problem that I am running into
is that Internet Explorer's "Save As" window defaults the filename to the
name of my servlet.  Firefox/Netscape will save the file as the filename
that I specify in the Content-Type HTTP header.
Does anyone know how to fix this?

Here is the code that I am currently using:

response.setContentType("text/xyz" );
response.setHeader("Content-Disposition", "Attachment;
filename=\"blah.xyz\"");

Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org