After updating to struts2-core-2.3.14.2, it gives me the following error during a download with Stream result:
Servlet.service() for servlet
It seems fine except that for a couple of things:
Specify the contentType:
text/plain
attachment;filename="${fileName}"
downloadFile
text/plain is the default, and in your example you have a txt file, but it is better to explicit it in the configuration;
Follow the JavaBeans Conventions; a getter should not have logic, and the name should match the one of the private variable returned:
For example,
String foo;
public String getBar(){
return this.foo;
}
is not valid and may cause problems to Struts2 (that makes use of Reflection internally)
Then try changing your Action code like this:
String filePathName="/home/download/aaa.txt";
String fileName;
InputStream donwloadFile;
public String getFileName() {
return this.fileName;
}
public InputStream getDownloadFile() {
return this.downloadFile;
}
public String download() throws Exception {
File file = new File(filePathName);
this.fileName = file.getName();
this.downloadFile = new BufferedInputStream(new FileInputStream(file));
return SUCCESS;
}