• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalStateException in JSP

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...???
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic