whqsoft 2010-05-09 19:47
浏览 198
已采纳

struts2下载问题

无论怎么认知,用迅雷下和IE8下下载 都是出现*.action文件,不能正常出现下载文件名和类型。
[code]public InputStream getDownLoadFile() throws FileNotFoundException {
this.setFile();
String realPath = ServletActionContext.getRequest().getRealPath(
"/upload");
InputStream inputStream = new FileInputStream(realPath+"/"+this.file);
return inputStream;

}[/code]

在downloadAction中 代码如上
在下载端头文件如下:
Server Apache-Coyote/1.1
Content-Disposition attachment;file="2.jpg"
Content-Type application/octet-stream;charset=ISO8859-1
Transfer-Encoding chunked
Date Sun, 09 May 2010 11:33:59 GMT

struts.xml配置文件如下:
[code="java"]

downLoadFile
application/octet-stream;charset=ISO8859-1
attachment;file="${file}"

[/code]

能正常下载,为什么会这样呢?求朋友们给个答案。

  • 写回答

5条回答 默认 最新

  • 拽拽的初行者 2010-05-09 19:50
    关注

    首先,想把字符集去掉

    然后,你的Aciton中有file属性吗?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?