ssh开发中,文件下载过程中出现错误Can not find a java.io.InputStream with the name [renderResult
在编写文件下载的过程中,点击下载,然后出现这个错误:Can not find a java.io.InputStream with the name [renderResult] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
异常trace如下:
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [renderResult] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:237)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
。。。。。
我的源代码如下,使用的annotation注解方式:
package org.xjtu.framework.modules.normalUser.action;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.xjtu.framework.core.base.model.User;
@ParentPackage("struts-default")
@Namespace("/web/user")
public class DownloadAction extends UserBaseAction {
private static final int BUFFEREDSIZE = 1024;
ByteArrayInputStream renderResult;
String downloadFileName = "";
private User user;
@Action(value = "downloadRenderResult", results = { @Result(name = ERROR, type="httpheader",params={"status","204"}),
@Result(name = SUCCESS, type = "stream", params = {
"contentType", "application/zip", "inputName",
"renderResult", "contentDisposition",
"attachment;filename=${downloadFileName}.zip", "bufferSize", "1024" })})
public String downloadRenderResult() throws Exception{
user = (User)session.get("user");
System.out.println(user.getName());
ByteArrayOutputStream output = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(output);
String path="/home/RenderFarm/apache-tomcat-6.0.37/logs/";
//user.getHomeDir()+"building/Pictures";
File file = new File(path);
this.downloadFileName="result";
zip(file,zos,"result");
//清空缓冲区数据,这一步务必先执行
zos.flush();
zos.close();
byte[] ba = output.toByteArray();
renderResult=new ByteArrayInputStream(ba);
System.out.println(renderResult);
output.flush();
output.close();
return SUCCESS;
}
private synchronized void zip(File inputFile, ZipOutputStream out, String base)
throws IOException {
if (inputFile.isDirectory()) {
File[] inputFiles = inputFile.listFiles();
out.putNextEntry(new ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < inputFiles.length; i++) {
zip(inputFiles[i], out, base + inputFiles[i].getName());
}
} else {
if (base.length() > 0) {
out.putNextEntry(new ZipEntry(base));
} else {
out.putNextEntry(new ZipEntry(inputFile.getName()));
}
FileInputStream in = new FileInputStream(inputFile);
try {
int c;
byte[] by = new byte[BUFFEREDSIZE];
while ((c = in.read(by)) != -1) {
out.write(by, 0, c);
}
} catch (IOException e) {
throw e;
} finally {
in.close();
}
}
}
}
求大神帮忙解惑,我在网上也搜了不少,按照那个做搞不好,是不是代码有什么问题?