Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletOutputStream is not working?

 
Maruli Lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Maruli Lee
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
  • 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()
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic