当前位置: 代码迷 >> Java Web开发 >> struts2 文件下载 struts.xml配置有关问题
  详细解决方案

struts2 文件下载 struts.xml配置有关问题

热度:1981   发布时间:2013-02-25 21:20:18.0
struts2 文件下载 struts.xml配置问题
在struts.xml配置文件下载如下:

XML code
<action name="download" class="com.test.Action.DownloadAction">    <result name="success" type="stream">        <param name="contentType">application/vnd.ms-excel</param>        <param name="contentDisposition">filename="struts.xsl"</param>        <param name="inputName">downloadFile</param>    </result></action>


问题是
XML code
<param name="contentType">application/vnd.ms-excel</param><param name="contentDisposition">filename="struts.xsl"</param>


文件名称和文件类型都是写死在xml里面的。 如何让文件下载功能的文件名和文件类型能够动态的加载呢?

谢谢



------解决方案--------------------------------------------------------
那两个配置参数不是必须的。

HttpServletResponse rp = (HttpServletResponse)ctx.get( StrutsStatics.HTTP_RESPONSE );
// 指定下载文件名称
rp.setHeader("Content-Disposition", 
"attachment; filename=\"" +filename + "\"");
------解决方案--------------------------------------------------------
在域中设置两个值有get/set,通过${xxx}取。
  相关解决方案