• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File is Not Displaying

 
Steve Dyke
Ranch Hand
Posts: 1621
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are calling both getOutputStream and getWriter. Also, what's with emitting the trailing html closing tags? This code looks very suspect.
 
Steve Dyke
Ranch Hand
Posts: 1621
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1621
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1621
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getJSON expects you to return JSON. It looks like you are trying to return a PDF.
 
Steve Dyke
Ranch Hand
Posts: 1621
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 exists
  • If it does not, it returns JSON error info
  • If it does, it returns JSON that contains the URL of another servlet that will stream the PDF
  • The client takes that URL, and uses it to display the drawing in another window or iframe
  •  
    Steve Dyke
    Ranch Hand
    Posts: 1621
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks. It works great.
     
    joseph prabhu
    Ranch Hand
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Bartender
    Posts: 543
    4
    Java Netbeans IDE Redhat
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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!
     
    joseph prabhu
    Ranch Hand
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 162
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    my jsp code is

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic