日期:2014-05-17  浏览次数:20989 次

struts2导出excel无法找到InputStream
错误:java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [] in the invocation stack. Check the <param name="inputName"> tag specified for this action

说是我栈中没有excelStream。

环境:struts2.3.15+spring3+hibernate4
其他环境有:druid+javamelody

使用的是jxl导出excel
从数据库查询数据,不是读取的文件。
action:


public String filename;
public InputStream excelStream;
get、set方法省略....

public String exportExcel() {
ByteArrayOutputStream targetFile = new ByteArrayOutputStream();
try {
WritableWorkbook workbook = Workbook.createWorkbook(targetFile);
WritableSheet sheet = workbook.createSheet("测试报告", 0);
       ......其他省略
        workbook.write();
workbook.close();
        } catch (Exception e) {
System.out.println("在输出到EXCEL的过程中出现错误,错误原因:" + e.toString());
}
excelStream = new ByteArrayInputStream(targetFile.toByteArray());
       System.out.println("===================================="+excelStream);
}

struts配置文件:

<result name="excel" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="inputName">excelStream</param>
<param name="contentDisposition">attachment;filename="test.xls"</param>
<param name="bufferSize">1024</param>
</result>

打印出来的inputStream:
====================================java.io.ByteArrayInputStream@124a60b
不是空的啊。
在struts2.18中也是使用的同样的方法,可以导出,但这是什么个情况?,请教大神,很急!!!

------解决方案--------------------
你这个action方法中没有return?!
------解决方案--------------------
如果没有读到这个excel,也就是没有流也会出现这个这个错误的。
------解决方案--------------------
既然用struts了,就要遵从人家的规则,你把流传给excelStream试试,有set、get方法有啥用,又没值。
------解决方案--------------------
<!-- 导出excel -->
<action name="daochuexcel" class="com.wuliuguanli.action.DaochuExcelAction">   
            <result name="excel" type="stream">   
                <param name="contentType">application/vnd.ms-excel</param