Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in writing to the response output stream through the included jsp

 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code fragment from the included jsp.
This jsp is intended to write an image (jpg) to the main jsp



Exactly the "response.getOutputStream()" is throwing the IllegalStateException

java.lang.IllegalStateException
at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(ServletResponseWrapperInclude.java:63)
at org.apache.jsp.captcha_jsp._jspService(captcha_jsp.java:192)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.ap


Can someone help me on this?
The jsp is included through <jsp:include page=....></jsp:include> action
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shwetha Sharma wrote:



Use Servlet . dont do this stuff in jsp
 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
Use Servlet . dont do this stuff in jsp


Actually my doubt is in a jsp since we can use the out object to write to the current stream, what coud be used in the included jsp to contibute in the response if the included jsp is creating a dyamic content and want to write it to the main jsp.

As in my case i am dynamically creating an image and want to include that created image in the main jsp. I am not doing this job in the servlet method as it is already getting some dynamic content from the database and storing it in session.Then it is forwarding it to the main jsp in which i want to show my dynamically created image.
I am not writing any content to the response in the servlet method so I have done this stuff in the included jsp.

Any help would be appriciated
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're doing it wrong.

All a JSP can do is to create an HTML file to send the browser. What is it going to do with the image data? If you were writing this as HTML, would you embed the image data directly in the HTML? Of course not. So you can't do that with a JSP either.

The same method used to put imags into an HTML page must be used with JSP; in other words, an <img> tag, whose src can be a servlet (not a JSP) that streams the image data.

 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
The same method used to put imags into an HTML page must be used with JSP; in other words, an <img> tag, whose src can be a servlet (not a JSP) that streams the image data.



Thanks it worked.
I used the image src as servlet that streams a image data
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic