• Post Reply Bookmark Topic Watch Topic
  • New Topic

IllegalStateException in JSP  RSS feed

 
akbar thobani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Author: athobani Sep 27, 2002 11:40 AM

I am fairly new to JSP and having problem with this piece of code, any insight will be appreciated. thanks
<%@ page contentType="application/vnd.ms-excel" autoFlush="false"
import="java.io.*, org.apache.poi.hssf.usermodel.HSSFWorkbook"
%>
<jsp:useBean id="FRNW" class="jsptutorial.JSPExcelUsingHSSFBean" scope="application" />
<%
try {
HSSFWorkbook wb = FRNW.createSheet() ;
ServletOutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
} catch (Exception e) {
out.println("error in JSP");
}
%>
the code works and output what I excpected to see, but produce this error message on server. "java.lang.IllegalStateException: getOutputStream() has already been called for this response"
any idea what's going on...???
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP automatically creates the variable "out" by getting an output stream from the response. Therefore your line

causes the exception you see.
Somewhere on the java.sun.com there is a lovely short summary of JSP technology syntax that shows the syntax for the various tags and includes a list of the "Implicit objects" such as out - that JSP automatically creates. Unfortunately I have lost track of where they are keeping it after the most recent reorganization.
Bill
 
akbar thobani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats is my delima, how do I write an object out if the syntax for write method is.
HSSFWorkbook write(OutputStream o)
Since the "out" is a type of JspWriter object, how do I get the outputstream to write, Please comment. thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple answer is - it is just about impossible to write non-character data from a JSP. The whole JSP API is designed to write character data. If the class you are using doesn't have a write method that uses a Writer, you should redesign your application to use a servlet for that particular function.
Bill
[ October 01, 2002: Message edited by: William Brogden ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!