struts2 文件下载不成功

Autuming 2016-04-23 10:10:09
今天要使用struts2 的文件下载,先写了个demo,怎么也调不通,请大家指导一下。
后台代码:
public class DownloadFileAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -4434797914813536697L;
private InputStream inputStream;
private String fileName;
private long contentLength;

public String execute() throws FileNotFoundException {

File fileToDownload = new File("D:/DownLoad/fileABC.txt");

inputStream = new FileInputStream(fileToDownload);
fileName = fileToDownload.getName();
contentLength = fileToDownload.length();

return SUCCESS;
}

struts.xml 文件:
<package name="Struts2FileDownload" extends="struts-default">

<action name="downloadFile" class="com.ryf.action.DownloadFileAction">
<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">4096</param>
</result>
</action>

</package>

前台代码:
<%@ 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>
<title>Download File</title>
</head>
<body>
<h1 align="center">Struts2 File Download Demo</h1>
<h3 align="center">
<a href="/downloadFile.action">Download this file</a>
</h3>
</body>
</html>

报错信息:HTTP Status 404 - /downloadFile.action
...全文
105 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2016-04-23
  • 打赏
  • 举报
回复
Struts2FileDownload/downloadFile

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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