Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

java.lang.IllegalStateException: strict servlet API : cannot call getWriter after getOutputStream()



Hi,
My servlet is as follows. It just opens a dialog on the basis of the filetype. The filetype can be html, xml, csv or pdf.

<%@ page contentType="text/xml; charset=UTF-8"
<%
JspHelper jspHelper = new JspHelper();

FlexibleReportJobJspBean jspBean = new FlexibleReportJobJspBean();
FlexibleReportJob reportBean = jspBean.getFlexReportConvBean();
try
{
String reportCode = request.getParameter("reportCd");
String fileName = request.getParameter("fileName");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String generationDate = request.getParameter("generationDate");
Date reportDate = df.parse(generationDate);

byte[] data = reportBean.getReportData(reportCode, reportDate, fileName);
if(data == null || data.length == 0)
{
response.setContentType("text/html");
%>

var critErrMsg4 = getProperty("noFileToView");alert(" "+critErrMsg4);window.close();
<%
}
else
{
response.reset();
response.resetBuffer();
response.setHeader("content-disposition","attachment;filename=" + fileName);
ServletOutputStream servletOutputStream = response.getOutputStream();
servletOutputStream.write(data);
servletOutputStream.flush();
//out.clearBuffer();
//out = pageContext.pushBody();
}
}
catch (Exception ex)
{
JspLogger.logException("ReportDownload._Service",ex);
if (jspHelper.handleException(ex))
return;
}
%>

However this servlet runs fine on Weblogic 92. On Websphere 6.1 , it gives the following exception:

[9/25/09 19:02:16:037 EEST] 00000024 ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: /templates/flexiblequeries/jsp/ReportDownload.jsp. Exception thrown : java.lang.IllegalStateException: strict servlet API : cannot call getWriter after getOutputStream()