File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream" Watch "java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream" New topic
Author

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

Akash Wairagade
Greenhorn

Joined: Jul 11, 2008
Posts: 1
hi ,
i am getting below error while trying to implement export to excel functionality in Icefaces



HttpServletResponse response =(HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();;
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=name.xls");

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
// declare a row object reference
HSSFRow row = null;
// declare a cell object reference
HSSFCell cell = null;
row = sheet.createRow(1);

cell = row.createCell((short) 0);
cell.setCellValue(100);

workbook.write(response.getOutputStream());

response.getOutputStream().flush();
return null;


org.icefaces.impl.application.ExtendedExceptionHandler handle
WARNING: queued exception
java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()

thanks in advance
Akash
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Welcome to the JavaRanch, Akash!

JSF is designed to process and display HTML. Excel is a proprietary non-HTML format, so JSF is not a good rendering engine for it. Instead, put the Excel output code in a standard (non-JSF) servlet. You can then put the servlet's URL on a JSF page using an h:outputLink or similar connector.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream
 
Similar Threads
Response Filter
probelms with response.getOutputStream
cannot call getoutputstream( ) after getwriter( )
excel file generation in weblogic portal
OutputStream in Jsp