The fact is that I set content disposition programatically in the following line

getServletResponse().setHeader("Content-Disposition",
                ("attachment;filename=\"" + 
attachment.getName().trim().replaceAll(" ", "_") + "\""));
in the action as opposed to configuration. I was working with no issue until a 
month ago for over a year and suddenly it has stopped working



----- Original Message -----
From: Eric Lentz <eric.le...@sherwin.com>
To: Struts Users Mailing List <user@struts.apache.org>
Cc: 
Sent: Friday, January 13, 2012 11:22:02 AM
Subject: Re: File download fails in Firefox and Chrome

> Not setting the Content-disposition is header, makes the firefox to 
prompt for the download but it uses the action for filename ie 
Ticket.action. > Has anyone faced a similar issue or can provide a hint on 
how to fix the issue

Yep, saw this problem just this week.

I ran the request through software that would allow me to view the header 
and I saw that only the filename appeared in the contentDisposition, no 
"filename="...
Add a field to your action class called contentDisposition and assign it 
like this:
contentDisposition = "filename=\"" + filename + "\"";

This assumes you are using the stream result in a manner similar to this:
        <result name="myDownloadName" type="stream">
                <param name="bufferSize">1024</param>
        </result>

I included the contentDisposition in the result like this:

        <result name="myDownloadName" type="stream">
                <param name="contentType">${contentType}</param>
                <param 
name="contentDisposition">filename=${contentDisposition}"</param>
                <param name="bufferSize">1024</param>
        </result>

But that didn't work, because Struts took whatever was in my 
contentDisposition in my action versus using the param. So _the above 
doesn't work_ because it would drop the "filename=" portion. If you used a 
different variable name, then it would probably work, but I didn't go back 
and try. In theory, this would work:

        <result name="myDownloadName" type="stream">
                <param name="contentType">${myContentType}</param>
                <param 
name="contentDisposition">filename=${myContentDisposition}"</param>
                <param name="bufferSize">1024</param>
        </result>

Assuming you had myContentType and myContentDisposition in your action.

Hope that helps.

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

Reply via email to