duplicate headers received from server using Struts2 [duplicate]

痴心易碎 提交于 2020-01-06 02:30:25

问题


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';");

回答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(){ ... }



回答2:


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.



来源:https://stackoverflow.com/questions/27836375/duplicate-headers-received-from-server-using-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!