【发布时间】:2015-01-08 09:05:30
【问题描述】:
我在一个应用程序中使用 Struts2。我需要下载 excel 文件(.xlsx 和 .xls 格式)。这在 IE 中正常工作,但在 Chrome 中显示错误
“从服务器收到重复的标头”
我在文件名前使用引号(“
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>
我已经提到了动作类中的内容配置
static final private String Content = "Content-Disposition";
HttpServletResponse response = this.getHttpResponse();
response.setHeader(Content, "attachment;filename='Export.xlsx';");
【问题讨论】:
-
如果您使用的是
stream结果,那么也可以使用它来设置内容处置标头。 -
@AleksandrM 我已经通过动作类使用了内容配置。这就是你要我尝试的吗?我无法得到你。能详细解释一下吗?
-
stream结果已设置此标头,您正在添加另一个标头,因此出现此错误。阅读有关stream结果的文档。
标签: java http struts2 http-headers content-disposition