wrirting Data to Excel form JSP

I want to write data into 2 tabs of the same excel through JSP. I am using JakartaPOI api for this

this is the code

HSSFWorkbook wb =new HSSFWorkbook();

//creating 2 tabs

HSSFSheet spreadSheet = wb.createSheet("TAB1");

HSSFSheet s1 = wb.createSheet("TAB2");

HSSFRow row = spreadSheet.createRow(0);

HSSFCell cell = row.createCell((short) 0);

HSSFRow row1= s1.createRow(0);

HSSFCell cell1 = row1.createCell((short) 0);

FileOutputStream output =new FileOutputStream(new File("Users.xls"));

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-

Disposition", "attachment;filename=Users.xls");

ServletOutputStream servletOutputStream =

response.getOutputStream();

wb.write(servletOutputStream);

servletOutputStream.close();

This code works fine and through this i am able to open a excel woth two tabs.But in the background "IllegalStateException" is thrown.

Reson for the Exception:In the jsp page there is the implicit "out" object which is the PrintWriter object which in turn is a character stream object .Using one "response" we can get only one stream object which the already available out object but am in need of byte stream object to writer the excel file into the response stream.

Please somebody can tell is there a ohter method to create excel sheet with two tabs through JSP.

[1816 byte] By [anurag_coola] at [2007-11-26 17:53:59]
# 1
Are u writing this code in jsp..if so, change this code ServletOutputStream servletOutputStream = response.getOutputStream();wb.write(servletOutputStream);to wb.write(out.GetOutputStream());regardsShanu
mshanua at 2007-7-9 5:07:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
There is no method as such(getOutputStream())
anurag_coola at 2007-7-9 5:07:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

FileOutputStream output = new FileOutputStream(new File("/tmp/Users.xls"));

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-Disposition", "attachment;filename=Users.xls");

ServletOutputStream out = response.getOutputStream();

wb.write(output);

output.flush();

output.close();

use this code..

shanu

mshanua at 2007-7-9 5:07:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

this code is not working at all. No two tabs are coming.

Same IllegalStateException is thrown in the background

Why you declared a ServletOutputStream object even if you are not using it. it will give compilation program as "out" obj is already present and you are declaring the same name object

anurag_coola at 2007-7-9 5:07:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
pls post ur entire jsp as well as stack trace...regardsShanu
mshanua at 2007-7-9 5:07:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
thanks for help. Problem solved.instead of writing excel in jsp, Now i am doing all this writing in servlet.
anurag_coola at 2007-7-9 5:07:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Good... :)))
mshanua at 2007-7-9 5:07:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...