使用Struts2从服务器收到的重复标头 [英] duplicate headers received from server using Struts2

查看:176
本文介绍了使用Struts2从服务器收到的重复标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用Struts2。我需要下载excel文件(.xlsx和.xls格式)。这在IE中正常运行但在Chrome中显示错误

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"

我在文件名前使用引号(<文件名)。仍然没有使用chrome。下面是我的应用程序中使用的代码片段。

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

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


推荐答案

您可以设置 contentDisposition 与你设置其他标题的方式相同:在struts配置中。

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>

您也可以使用 $ {} 表示法,在Action中有相应的getter:

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

这篇关于使用Struts2从服务器收到的重复标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆