求高手,大神帮忙看看.....

huangwmflymysky 2013-10-27 05:10:44
我做一个struts2的下载,但是,弹不出保存的对话框,整了很久都没有效果,一看,才知道,
就是Content-Disposition:返回为空。

我的struts配置是:

<action name="download" class="fileLoadAction" method="download">
<result name="success" type="stream">
<param name="inputName">downloadFile</param>
<param name="contentType">${mimeType}</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">100000</param>
</result>
</action>

代码如下:
public String getFileName(){
try {
return new String(fileName.getBytes(), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return this.fileName;
}
}
public void setFileName(String fileName) {
try {
this.fileName = new String(fileName.getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String download(){
mimeType = context.getMimeType(fileName);
return "success";
}
public InputStream getDownloadFile() throws UnsupportedEncodingException
{
String path = "/file/";
// 取得目录文件流返回。
inStream = context.getResourceAsStream(path+fileName);
return inStream;
}

求各位能给看看是什么情况,谢谢了。


...全文
425 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Defonds 2013-10-28
  • 打赏
  • 举报
回复
你后台怎么把 fileName 传给前台的
MC-热狗 2013-10-28
  • 打赏
  • 举报
回复
filename="${fileName}" 这个不加引号试试
teemai 2013-10-27
  • 打赏
  • 举报
回复

response.setAttribute("contentType",xxx)
huangwmflymysky 2013-10-27
  • 打赏
  • 举报
回复
自己先顶一个....

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧