This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stream & JSP

 
Jamal Romero
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed like you are getting the output stream twice. Any reason for that? Can you post some more code?
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jamal Romero
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic