Mailing List
Home
Forum Home
Maven - Project building tool
Axis - Java SOAP implementation
Cocoon - MVC web framework based on XML/XSL
Lucene - Full-featured text search engine APIs
Log4J - A log library
Fop - Create PDF, PCL, PS, SVG, XML driven by XSL formatting objects.
POI - Java Excel, Word and other Microsoft Office files manipulating library
Oracle database error code ...
Subjects
log4j warning: No appenders could be found
java security AccessControlException: access denied (java io FilePermission clie
java lang InstantiationException: org apache tools ant Main
Apache Axis Tutorial
Struts <logic iterate >
log4j properties How to parse outpu to multiple files
configuring log4j with BEA Weblogic 8 1
How to use XSL FOP Java together
JSP precompile
Servlet File Download dialog problem (IE6,Adobe 6 0)
Proposal: Adding jar manifest classpath in jar and war plugins
Unsupported major minor version 48 0 problem while running the an
   telope task
java security AccessControlException: access denied (java io FilePermission
axis wsdl2java Ant Task usage
net sf hibernate MappingException: Error reading resource: test/User hbm xml
Building EAR ANT Script for websphere 5 0
CREATING WAR Files
jsp data into Excel
Classpath problem
Jboss 3 2 3+ vs Tomcat Axis Question
RE: How to include jars and add them into the MANIFEST MF/Class Path
attribute
Printing problem
InstantiationException
Couldn 't find trusted certificate
Please : How can one install ant 1 6 0 under Eclipse 2 1 ?
Excel: Too many different cell formats
Running junit tests fails
XDoclet, Struts and Maven: Where to start? SOLUTION
1 3 final: now giving me java io FileNotFoundException (Too many
open files)
AXIS: tomcat timeout ?
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
jsp data into Excel

jsp data into Excel

2003-12-30       - By Michael Zalewski

 Back
Reply:     1     2     3     4  

It will work.

The IllegalStateException is because you have written something out to the
JspWriter (out in a JSP page), then writing binary data to
response.getOutputStream().

In the Servlet API, you can do either one or the other, but not both.

Most likely, you are actually trying to write to the JspWriter (out) *after*
you have sent the workbook to response.getOutputStream(). This is most
likely white space that occurs after your closing '%>' but before the end of
file.

<%
      HSSFWorkbook wb =  new HSSFWorkbook();
      HSSFSheet s = wb.createSheet();
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-Disposition","attachment; filename
=unknown.xls");
      OutputStream out = response.getOutputStream();
      wb.write(out);
      out.close();
%>  **This line is the same as 'out.println();'

By the way, the problem happens at the beginning of the JSP page as well.
For example, most JSP pages begin with

<%@ page language="java" %> ** this end-of-line is the same as
'out.println();'
<%@ page import="java.util.*" %> ** this end-of-line puts another
'out.println();'
<%@ page import="org.apache.poi.hssf.usermodel.*" %> ** and another...
<%
      HSSFWorkbook wb =  new HSSFWorkbook();
      HSSFSheet s = wb.createSheet();

This is why, if you look at a JSP page through Internet Explorer, then use
IE's View | Source menu command, you see a lot of blank lines at the top of
the page.

However, the good news is, if you write only a small amount to the character
stream (JSP 'out'), you are allowed to start over on the binary stream
('response.getOutputStream()'). Exactly how much you are allowed to send to
the character output stream without an error depends on your application
server. But it seems to be like 2K in most cases.

The point is that JSP wants to write the response to its character output
stream. But to send a binary workbook in the response, you need to use the
binary output stream that is returned by 'response.getOutputStream()'. So
you have to make sure that the character output stream does not get mixed
in. But as I have already explained, JSP will automatically send a
End-Of-Line to the character stream after each closing %>

The solution I have found is to put a 'return;' after the workbook is
complete.  I also indent my <% and %> kind of weird. Not really necessary,
but weird matches my personality :). When you put your JSP tags this way,
there is no extra white space sent to the character stream.

<%@
      page language="java"
%><%@
      page import="java.util.*"
%><%@
      page import="org.apache.poi.hssf.usermodel.*"
%><%
      HSSFWorkbook wb =  new HSSFWorkbook();
      HSSFSheet s = wb.createSheet();
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-Disposition","attachment; filename
=unknown.xls");
      OutputStream out = response.getOutputStream();
      wb.write(out);
      out.close();
      return;
%>

Try the above -- add a return after your out.close() - and let us know how
well it works

-- --Original Message-- --
From: Srilatha [mailto:sei@(protected)]
Sent: Tuesday, December 30, 2003 3:14 AM
To: poi-user@(protected)
Subject: jsp data into Excel

Hi,
I want to export the contents of html page(JSP)  to Excel.The jsp  page
will be displayed on the browser and on the click of a button I need to
export the data into excel.On my page I have charts and also normal tables.
I have tried doing this but I'm getting illegalStateException..may be
bcoz its already written the jsp page and I'm trying to write the same
thing again ...
First of all is it possible to write the  contenets of this html page
into an Excel sheet???
Can u plz help

The code whcih I have written is like this....

      HSSFWorkbook wb =  new HSSFWorkbook();
      HSSFSheet s = wb.createSheet();
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-Disposition","attachment; filename
=unknown.xls");
      OutputStream out = response.getOutputStream();
      wb.write(out);
      out.close();

Thanks.



-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe, e-mail: poi-user-unsubscribe@(protected)
For additional commands, e-mail: poi-user-help@(protected)


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe, e-mail: poi-user-unsubscribe@(protected)
For additional commands, e-mail: poi-user-help@(protected)




Earn $52 per hosting referral at Lunarpages.