亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在struts2.3框架下文件的下載沒有文件名,但是可以在action中看到fileName是有傳進來的

在struts2.3框架下文件的下載沒有文件名,但是可以在action中看到fileName是有傳進來的

落子鳶 2017-03-19 17:31:51
acrion public?class?DownloadAction?extends?ActionSupport?{ ?private?String?fileName; ? ?public?String?getFileName()?{ ??return?fileName; ?} ?public?void?setFileName(String?fileName)?{ ??this.fileName?=?fileName; ?} ?public?InputStream?getInputStream()?throws?FileNotFoundException{ ??System.out.println(fileName); ??return?new?FileInputStream("D:\\qq\\"+fileName); ?} ? ? ?public?String?download(){ ??return?Action.SUCCESS; ?} } struts.xml <action?name="download"?class="jsh.sturts.action.DownloadAction" ???method="download"> ???<result?name="success"?type="stream"> ????<param?name="contentType">text/plain</param> ????<param?name="inputName">inputStream</param> ????<param?name="contentDisposition">attachment;filename="${fileName}"</param> ????<param?name="bufferSize">1024</param> ???</result> ??? ??? ???<%@?page?language="java"?contentType="text/html;?charset=UTF-8" ????pageEncoding="UTF-8"%> <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8"> <title>Insert?title?here</title> </head> <body> ????????????<a?href="download?fileName=1232323.doc">doc</a> </body> </html> 問題出在哪里了
查看完整描述

1 回答

?
落子鳶

TA貢獻2條經驗 獲得超2個贊

問題已經解決
在getFileName中把return?this.fileName;替換為
return?new?String(fileName.getBytes(),?"ISO8859-1");


查看完整回答
1 反對 回復 2017-03-19
  • 1 回答
  • 0 關注
  • 1920 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號