1

I am using Struts2 in an application. I need to download excel file(.xlsx and .xls formats). This is working properly in IE but in Chrome it is showing error

"Duplicate headers received from server"

I use quotes before the file name("<File Name"). Still it is not working in chrome. Below is the code snippets used in my application.

struts.xml

<action name="*Excel" method="{1}" class="ReportUtilityAction">
    <result name="success" type="stream">
        <param name="contentType">application/vnd.ms-excel</param>
        <param name="inputName">fileInputStream</param>
        <param name="bufferSize">1024</param>
    </result>
</action>

I have mentioned the content-disposition in the action class as

static final private String Content = "Content-Disposition";

HttpServletResponse response = this.getHttpResponse();
response.setHeader(Content, "attachment;filename='Export.xlsx';");
Cœur
  • 37,241
  • 25
  • 195
  • 267
Anju
  • 33
  • 6
  • If you are using `stream` result then use it to set content disposition header also. – Aleksandr M Jan 08 '15 at 09:11
  • @AleksandrM I have used the content disposition through action class. is that what you have asked me to try? I am not able to get you. Could you explain in detail? – Anju Jan 08 '15 at 09:25
  • `stream` result already sets this header and you are adding another one hence this error. Read docs about `stream` result. – Aleksandr M Jan 08 '15 at 09:42

2 Answers2

1

You can set contentDisposition in the same way you've set the other headers: in struts configuration.

<result name="success" type="stream">
    <param name="contentDisposition">attachment;filename="Export.xlsx";</param>
    <param name="contentType">application/vnd.ms-excel</param>
    <param name="inputName">fileInputStream</param>
    <param name="bufferSize">1024</param>
</result>

You can also have it parameterized by using the ${} notation, with a corresponding getter in the Action:

<param name="contentDisposition">attachment;filename="${filename}";</param>
public String getFilename(){ ... }
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

The error means that the header field is set twice; you should be able to see that in an HTTP trace. Thus you need to find out why it's set twice.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98