You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe Lam <jo...@moni-media.net> on 2007/08/30 14:33:49 UTC

[S2] File Download Example in showcase doesn't work with contentType application/x-download using IE

try to make a file download action without opening the file.
I try the showcase file download example. change contentType to
application/x-download in struts.xml

&lt;param name="contentType"&gt;application/x-download&lt;/param&gt;

with firefox it works fine. with IE, it still open the gif in browser.

anyone could help? the stream result type is handy. don't think i should re
invent the wheel.

btw just for curious I try to stream the file by jsp. I do something like
this in jsp:

    stream=response.getOutputStream();
    response.setContentType("application/x-download");
    response.addHeader("Content-Disposition","attachment;
filename="+filename);
    response.setContentLength( (int) f.length());
    blah blah blah to write data to stream

both IE and firefox are able to get the download dialog box but there is
exception in log file

ERROR [lina.core.StandardWrapperValve: 250] Servlet.service() for servlet
default threw exception
java.lang.IllegalStateException: getOutputStream() has already been called
for this response


I think stream result type should be the best solution. but I cant make IE
to download the file. Any help? 
Thank you very much

Joe
-- 
View this message in context: http://www.nabble.com/-S2--File-Download-Example-in-showcase-doesn%27t-work-with-contentType-application-x-download-using-IE-tf4353956.html#a12406179
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] File Download Example in showcase doesn't work with contentType application/x-download using IE

Posted by Joe Lam <jo...@moni-media.net>.
Thanks so much. was missing attachment; in param contentDisposition
(both examples in showcase do not have this)

regarding exception in jsp, I just put the streaming stuff to action (return
null result). thats fine.

Thank you very much.




Jeromy Evans - Blue Sky Minds wrote:
> 
> IE6 displays the image inline because it recognises the extension of the 
> file in preference to the mime type.
> 
> The stream result allows you to set the Content-Disposition header, as 
> you have already done in your JSP code.
> 
> attachment; filename=${fileName}
> 
> This disposition will ensure the file is downloaded as file (almost) 
> irrespective of the mime type.  If you provide a getFileName() property 
> in your action the notation ${fileName} will read it (this is allowed in 
> struts.xml).   Otherwise you can simple hardcode the filename to 
> something useful.
> 
> The exception you quoted is unrelated and caused because you're writing 
> to the output stream within a JSP that's already doing so.  That code is 
> better suited to its own servlet.
> 
> Hope that helps,
> regards,
>  Jeromy Evans
> 
> Joe Lam wrote:
>> try to make a file download action without opening the file.
>> I try the showcase file download example. change contentType to
>> application/x-download in struts.xml
>>
>> &lt;param name="contentType"&gt;application/x-download&lt;/param&gt;
>>
>> with firefox it works fine. with IE, it still open the gif in browser.
>>
>> anyone could help? the stream result type is handy. don't think i should
>> re
>> invent the wheel.
>>
>> btw just for curious I try to stream the file by jsp. I do something like
>> this in jsp:
>>
>>     stream=response.getOutputStream();
>>     response.setContentType("application/x-download");
>>     response.addHeader("Content-Disposition","attachment;
>> filename="+filename);
>>     response.setContentLength( (int) f.length());
>>     blah blah blah to write data to stream
>>
>> both IE and firefox are able to get the download dialog box but there is
>> exception in log file
>>
>> ERROR [lina.core.StandardWrapperValve: 250] Servlet.service() for servlet
>> default threw exception
>> java.lang.IllegalStateException: getOutputStream() has already been
>> called
>> for this response
>>
>>
>> I think stream result type should be the best solution. but I cant make
>> IE
>> to download the file. Any help? 
>> Thank you very much
>>
>> Joe
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--File-Download-Example-in-showcase-doesn%27t-work-with-contentType-application-x-download-using-IE-tf4353956.html#a12407791
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] File Download Example in showcase doesn't work with contentType application/x-download using IE

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
IE6 displays the image inline because it recognises the extension of the 
file in preference to the mime type.

The stream result allows you to set the Content-Disposition header, as 
you have already done in your JSP code.

<param name="contentDisposition">attachment; filename=${fileName}</param>

This disposition will ensure the file is downloaded as file (almost) 
irrespective of the mime type.  If you provide a getFileName() property 
in your action the notation ${fileName} will read it (this is allowed in 
struts.xml).   Otherwise you can simple hardcode the filename to 
something useful.

The exception you quoted is unrelated and caused because you're writing 
to the output stream within a JSP that's already doing so.  That code is 
better suited to its own servlet.

Hope that helps,
regards,
 Jeromy Evans

Joe Lam wrote:
> try to make a file download action without opening the file.
> I try the showcase file download example. change contentType to
> application/x-download in struts.xml
>
> &lt;param name="contentType"&gt;application/x-download&lt;/param&gt;
>
> with firefox it works fine. with IE, it still open the gif in browser.
>
> anyone could help? the stream result type is handy. don't think i should re
> invent the wheel.
>
> btw just for curious I try to stream the file by jsp. I do something like
> this in jsp:
>
>     stream=response.getOutputStream();
>     response.setContentType("application/x-download");
>     response.addHeader("Content-Disposition","attachment;
> filename="+filename);
>     response.setContentLength( (int) f.length());
>     blah blah blah to write data to stream
>
> both IE and firefox are able to get the download dialog box but there is
> exception in log file
>
> ERROR [lina.core.StandardWrapperValve: 250] Servlet.service() for servlet
> default threw exception
> java.lang.IllegalStateException: getOutputStream() has already been called
> for this response
>
>
> I think stream result type should be the best solution. but I cant make IE
> to download the file. Any help? 
> Thank you very much
>
> Joe
>   


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