Can anyone tell me why do I get the
Servlet exception - "OutputStream already obtained" for the below code?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="com.aig.cruis.actionform.GenericExcelActionForm"%>
<%@ page import="com.aig.cafe.framework.util.IDataCapsule,com.aig.cruis.utils.AppValueFactory"%>
<%@ page import="com.aig.cafe.framework.util.FWConstants,com.aig.cruis.common.UserBean, java.io.*"%>
<%
IDataCapsule dc = (IDataCapsule)request.getAttribute("RequestDataCapsule");
GenericExcelActionForm form = (GenericExcelActionForm)dc.getObject(FWConstants.ACTION_FORM);
String fileName = form.getFileName();
File f = new File(fileName);
if (f.exists()) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=" + form.getReportType() + ".xls");
FileInputStream fileInputStream = new FileInputStream(fileName);
OutputStream o = response.getOutputStream();
int i;
byte[] byteArr = new byte[256];
while ((i=fileInputStream.read(byteArr)) != -1) {
o.write(byteArr);
}
fileInputStream.close();
o.close();
File realFile = new File(fileName);
realFile.delete();
} else {
%>
Error Occurred...
<%
}
%>