我想问是否有人可以帮助我举个例子来使用 Struts 2 注释下载文件
我在我的动作课上试过这个
public class MyClass {
private InputStream fileInputStream;
private String fileName;
@Override
@Action(AbstractBasisAction.VIEW)
public String view() {
System.out.println("HoursCycleDownloadFrameAction: view");
super.view();
return SUCCESS;
}
public InputStream getFileInputStream() {
return fileInputStream;
}
@Action(value = "downloadFile", results = { @Result(name = "success", type = "stream", params = { "contentType", "application/octet-stream", "inputName", "fileInputStream", "contentDisposition", "filename=\"${fileName}\"", "bufferSize", "1024" }) })
public String downloadFile() throws Exception {
fileName = "license.txt";
fileInputStream = new FileInputStream(new File("C:\\", fileName));
return SUCCESS;
}
}
这就是我的页面包含的内容
<s:url id="fileInputStream" namespace="/myClass" action="downloadFile" ></s:url>
Download file - <s:a href="%{fileInputStream}">lisence.txt</s:a>
但现在的问题是它下载了带有操作方法名称的文件。表示文件名为downloadFile.action。任何人都可以帮助我吗?