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>
問(wèn)題出在哪里了
1 回答

落子鳶
TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超2個(gè)贊
問(wèn)題已經(jīng)解決 在getFileName中把return?this.fileName;替換為 return?new?String(fileName.getBytes(),?"ISO8859-1");
添加回答
舉報(bào)
0/150
提交
取消