Can not find a java.io.InputStream with the name [inputStream] in the invocatio

Can not find a java.io.InputStream with the name [inputStream] in the invocation

ava.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack. Check the 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:362)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
----------------------------------------------------------------------------------
解决方法:打印InputStream,如果为null,则问题找到了。fileName为空值导致InputStream中返回的ServletActionContext.getServletContext().getResourceAsStream(DOWNLOADFILEPATH+fileName)为null,报出以上异常,找到了异常的根源。
将文件路径打出来,发现fileName为空,即struts获取对象属性失败,然后对此问题进行相关处理,并解决。
==========================================================


strut2下载文件的“ <param name="inputName"> tag specified for this action.”异常

具体异常是这句话:

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.

1.文件路径不对,根本就没有取到文件。这种情况下,可以将获得InputStream的那条语句放在system.out.println()中输出一下,若为null,那就是路径不对了,或者说得准确些就根本没有找到文件。
2.在action中没有写配置文件中"<param name="inputName">"后面属性的那个get方法.
当以上两种情况都正确的情况下,问题就在这里了:
当采用 return ServletActionContext.getServletContext().getResourceAsStream("...") 这种方法获得输入流的时候,要保证文件位置在 ServletContext 当中,就是说要在当前的应用上下文中,
如果想要获得外部文件 譬如 D盘中的某个文件,那么就要自己创建输入流才可以,如:
File file = new File("D:\\spring.doc");
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package db; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class DBCon { Connection con = null; Statement st = null; ResultSet rs = null; String driver=null; String url = null; String username = null; String password = null; public Connection dbCon() { try { InputStream is=DBCon.class.getClassLoader().getResourceAsStream("db.properties"); Properties prop=new Properties(); try { prop.load(is); driver=prop.getProperty("driver"); url=prop.getProperty("url"); username=prop.getProperty("username"); password=prop.getProperty("password"); } catch (IOException e1) { e1.printStackTrace(); } Class.forName(driver); Class.forName("com.mysql.jdbc.Driver"); url = "jdbc:mysql:///sams?useUnicode=true&characterEncoding=utf8"; username = "root"; password = ""; try { con = DriverManager.getConnection(url, username, password); } catch (SQLException e) { e.printStackTrace(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } return con; } /* * 增删改 */ public int query(String sql) { int rs = 0; con = dbCon(); try { st = con.createStatement(); rs = st.executeUpdate(sql); } catch (SQLException e) { close(); e.printStackTrace(); } return rs; } /* * 查 */ public ResultSet find(String sql) { try { con = dbCon(); st = con.createStatement(); rs = st.executeQuery(sql); } catch (SQLException e) { close(); e.printStackTrace(); } return rs; } /* * 关闭数据库 */ public void close() { try { if (rs != null) rs.close(); if (st != null) st.close(); if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } }有错误
最新发布
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值