• 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

ServletOutputStream is not working?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a previous program which is working fine so I just copied the chunk of code and paste it on the new program which I am building. Basically my program will generate a report using JExcel API and then I will try to display it on the web so that user can Open/Save/Cancel it (the normal IE notification window). Furthermore, there is no error message on the tomcat log.



[ November 27, 2007: Message edited by: Maruli Lee ]
[ November 27, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this code in a servlet or a JSP?
 
Maruli Lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

It's in JSP, that's why I posted it under the JSP forum.

Additional info, this chunck of codes are embedded within

<form name="frm" method="POST">
//Code goes here
</form>
[ November 27, 2007: Message edited by: Maruli Lee ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are embedding the output in the middle of some HTML? Of course that won't work. What are you really trying to do?
 
Maruli Lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No no no. The codes are within the JSP tags <% %>

Actually my JSP will be calling a Java program which will generate a report in Excel (Using JExcel API). After the report is created it will be stored in C:\tomcat\webapps\SnetReport\REPORT

What I am trying to do is to pop up a save file dialog box so that the user can retrieve the file from the web instead of having to go into the folder to get it manually.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good rule of thumb is to not use the servlet output stream in a JSP, ever. As Bear said, it won't work. Theoretically, it might, but practically, it won't. Moving the code into a servlet will help.
 
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


Of course it won't - JSP has automagically already gotten the output stream for character output - thats what JSP do. You are undoubtedly getting a java.io.IllegalStateException thrown at that point. See the JavaDocs.

Bill
 
Maruli Lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have modified my code to avoid using OutputStream since it will cause a lot of problem. Now my modified code looks like this:



After I ran through this code my JSP page will refresh and show me this screen:



In addition, Tomcat shows following message:

Nov 29, 2007 10:44:38 AM org.apache.jasper.runtime.PageContextImpl release
WARNING: Internal error flushing the buffer in release()
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As has been mentioned, JSPs are designed for output of text.
Sending a binary file via JSP is tricky for a number of reasons.

I would recommend you read Bear's excellent article on this subject: The Secret Life of JavaServer Pages where he answers the question "Why does everyone tell me to use a servlet to send binary data to the browser? I wanna use a JSP!"

You've written it all in java code anyway - it SHOULD be a servlet.
 
And then the flying monkeys attacked. My only defense was this 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