wood burning stoves 2.0*
The moose likes JSP and the fly likes Stream & JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Stream & JSP" Watch "Stream & JSP" New topic
Author

Stream & JSP

Jamal Romero
Greenhorn

Joined: Jun 21, 2001
Posts: 9
Hi,
I want to get this working in a JSP. The following code is taken form a servlet:
ServletOutputStream ou = res.getOutputStream();
res is a HttpServletResponse reference.
in JSP I tried to use the implicite Object response. I tried:
<%
response.getOutputStream();
%>
I got an Internal Servlet Error:
java.lang.IllegalStateException: OutputStream is already being used for this request.
How can I get an outputstream reference in JSP.
Thanks
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
I noticed like you are getting the output stream twice. Any reason for that? Can you post some more code?


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by Jamal Romero:
Hi,
I want to get this working in a JSP. The following code is taken form a servlet:
ServletOutputStream ou = res.getOutputStream();
res is a HttpServletResponse reference.
in JSP I tried to use the implicite Object response. I tried:
<%
response.getOutputStream();
%>
I got an Internal Servlet Error:
java.lang.IllegalStateException: OutputStream is already being used for this request.
How can I get an outputstream reference in JSP.
Thanks

There is an implicit object 'out', though using it often indicates you might be better off writing a servlet instead of a JSP page.


Shawn Bayern<br />"JSTL in Action" <a href="http://www.jstlbook.com" target="_blank" rel="nofollow">http://www.jstlbook.com</a>
Jamal Romero
Greenhorn

Joined: Jun 21, 2001
Posts: 9
Hi,
The implicit Objet "out" available for JSP is of type:
java.lang.Object
|
+-java.io.Writer
|
+-javax.servlet.jsp.JspWriter
But what I need is :
java.lang.Object
|
+-java.io.OutputStream
|
+-javax.servlet.ServletOutputStream
I think I'll implement what I need using a Servlet.But there must be a way to do it in JSP. I looked on Jakarta Taglib and there's a response tag library.
What I have is a class having a method that takes as argument an outputstream, like:
amethod(OutputStream ou)
How can I use this method in JSP if the reference to "ou" is unavailable?
Thanks for the reply
Jamal
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by Jamal Romero:
Hi,
The implicit Objet "out" available for JSP is of type:
java.lang.Object
|
+-java.io.Writer
|
+-javax.servlet.jsp.JspWriter
But what I need is :
java.lang.Object
|
+-java.io.OutputStream
|
+-javax.servlet.ServletOutputStream
I think I'll implement what I need using a Servlet.But there must be a way to do it in JSP. I looked on Jakarta Taglib and there's a response tag library.
What I have is a class having a method that takes as argument an outputstream, like:
amethod(OutputStream ou)
How can I use this method in JSP if the reference to "ou" is unavailable?
Thanks for the reply
Jamal

The problem is that JSP is a textual medium; Writers handle text, while OutputStreams handle arbitrary bytes. Since in a JSP page, the underlying servlet's output is already accessed textually via a Writer, it is not generally safe to access it as a Stream too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stream & JSP
 
Similar Threads
OutputStream already obtained
puting println in a brief variable
How to invoke file downloading from the JSP?
How to print PDF from JSP?
OutputStream already obtained error