This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Akash Wairagade
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18023
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic