excelStreamI am trying to download an excel file.
In my Action class
public class ActivityTrackerExlReportAction extends BaseAction
{
private InputStream excelStream;
private UserMasterDTO userMasterDTO;
public InputStream getExcelStream()
{
return excelStream;
}
public void setExcelStream(InputStream excelStream) {
this.excelStream = excelStream;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
WorkbookSettings wbSettings = new WorkbookSettings();
try
{
response.setHeader("Content-Disposition", "attachment; filename=/timesheet.xls");
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(outputStream, wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
service.createLabel(excelSheet);
service.createContent(excelSheet);
workbook.write();
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
setExcelStream(inputStream);
workbook.close();
outStream.flush();
outStream.close();
}
catch(Exception e)
{
}
finally
{
// outStream.close();
}
return "generateReport
}
My struts.xml
contains:
<result type="stream" name="generateReport">
<param name="contentType">"application/vnd.ms-excel"</param>
<param name="inputName">excelStream</param>
<param name="bufferSize">1024</param>
</result>
I am using JXL
to create and write an Excel sheet. Why am i getting the error and how to get out of it? Can not find a java.io.InputStream
with the name [excelStream]
in the invocation stack
My are Stacktraces:
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [excelStream] 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) .......