struts2文件下载出现Can not find a java.io.InputStream with the name的错误

  1. Servlet.service() for servlet default threw exception   
  2. java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.   
  3.     at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)   
  4.     at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)   
  5.     at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)   
  6.     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)   
  7.     at com.best.top.validate.TopInterceptor.intercept(TopInterceptor.java:47)   
  8.     at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)   
  9.     at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)   
  10.     at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)   
  11.     at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)   
  12.     at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)   
  13.     at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)   
  14.     at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)  

 

 

刚看到这个文件 还以为是文件名写错了,反复换了好几次,还是不对,后来才发现,原来的获取不到inputStream这个方法.

不过网上也有许多这种错误,有的是获取不到文件路径的。

 

//在Actionkh 返回下载文件的二进制输入流对象的方法
 public InputStream getInputStream(){

  try {
   File file=new File(filepath+"/"+filename);
   InputStream is=new FileInputStream(file);
   return is;
   
  } catch (FileNotFoundException e) {
   e.printStackTrace();
   throw new RuntimeException("获取文件失败");
    }
 }

在struts.xml中的配置:

<package name="download" namespace="/" extends="struts-default">
   
   <action name="downloadAction" class="cn.itcast.web.download.DownloadAction" method="excute">
   <!-- 
   -->
   <param name="filepath">
       E:\Program Files\apache-tomcat-6.0.32\webapps\day34\download
   </param>
    <result name="download" type="stream">
     <param name="contentType">jpg/jpeg</param>
     <!-- 下载文件的打开方式 -->
     <param name="contentDisposition">attachment;filename="${filename}"</param>
     <!-- 获取下载文件的二进制输入流对象,即InputStream -->
     <param name="getinputName">inputStream</param>  
    </result>  
   </action>  
  </package>

 

在struts.xml中获取方法名时需要去掉get和(),然后将大写字母改为小写,如上的红色文字

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值