| Author |
File is Not Displaying
|
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
I am having two problems with this. First my file will not display, second I get a System Out Error. Please help. [11/6/08 14:38:01:891 CST] 00000033 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet ViewDrawing6. Exception thrown : java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
You are calling both getOutputStream and getWriter. Also, what's with emitting the trailing html closing tags? This code looks very suspect.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
Originally posted by Bear Bibeault: You are calling both getOutputStream and getWriter.
How do I fix this part?
Originally posted by Bear Bibeault: Also, what's with emitting the trailing html closing tags? This code looks very suspect.
I don't really understand this comment. Do any of these have anything to do with the file not displaying?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
Originally posted by Steve Dyke: How do I fix this part?
Easy. Don't do that. Fetch the response stream as either an output stream or a writer; not both.
I don't really understand this comment.
The code is useless and superfluous. What is it doing there? You're not emitting HTML, so why the needless output? [ November 06, 2008: Message edited by: Bear Bibeault ]
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
Originally posted by Bear Bibeault: Easy. Don't do that. Fetch the response stream as either an output stream or a writer; not both. [ November 06, 2008: Message edited by: Bear Bibeault ]
Okay, so how do I use this servlet response to write a file for display and then write a response back to my calling jQuery.getJSON call?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
You don't. You can't return two responses to a single request. You're going to need to back up and explain what it is that you are really trying to accomplish.
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
|
On my JSP I have a function that uses a jQuery.getJSON call to the servlet sending a url address as a parameter. It is supposed to display a drawing cooesponding to the url. If the url does not exist I want to return a flag to the calling JSP and display a message to that effect. If the url does exist I want to display the drawing. Right now the servlet code rus but no drawing is displayed.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
getJSON expects you to return JSON. It looks like you are trying to return a PDF.
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
Okay, I changed to jQuery.post and it still will not work. This will work if I put it directly in the link code This will not work if in the link code I have href="javascript:viewdrawing()" and viewdrawing() is What would be the difference?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
You can't return a drawing in an Ajax request. From what you said, here's what I'd suggest: Your Ajax request hits a servlet that checks if the drawing existsIf it does not, it returns JSON error infoIf it does, it returns JSON that contains the URL of another servlet that will stream the PDFThe client takes that URL, and uses it to display the drawing in another window or iframe
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
|
Thanks. It works great.
|
 |
joseph prabhu
Ranch Hand
Joined: Feb 26, 2008
Posts: 162
|
|
I got same exception as
Exception thrown : java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
my code is
Exception arises only when code start executing JSP page.
Could you please help?
|
 |
Dieter Quickfend
Ranch Hand
Joined: Aug 06, 2010
Posts: 280
|
|
Your code is not complete, but I suspect you're doing exactly what your exception message says. Trying to write multiple responses to one request. Are you using a RequestDispatcher to talk to a JSP after writing to the OutputStream?
What a JSP does is basically make an HTML page and write it to the response object. If you've already written to the response object and then you write a whole jsp page... then of course you get that exception. You can't write the response, and then dispatch to a JSP, because you've already written your response!
|
Oracle Certified Professional Java Programmer
|
 |
joseph prabhu
Ranch Hand
Joined: Feb 26, 2008
Posts: 162
|
|
I am using struts 1.1 , so the execute method return return mapping.findForward("success");
In struts.xml the jsp is defined. when the code starts executing the jsp it gives exception in server log , not in page. Page gets successfully loaded.
Thanks
|
 |
joseph prabhu
Ranch Hand
Joined: Feb 26, 2008
Posts: 162
|
|
my jsp code is
|
 |
 |
|
|
subject: File is Not Displaying
|
|
|