aspose file tools*
The moose likes Servlets and the fly likes File is Not Displaying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "File is Not Displaying" Watch "File is Not Displaying" New topic
Author

File is Not Displaying

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1479
    
    1
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: 61661
    
  67

You are calling both getOutputStream and getWriter. Also, what's with emitting the trailing html closing tags? This code looks very suspect.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1479
    
    1
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: 61661
    
  67

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: 1479
    
    1
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: 61661
    
  67

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: 1479
    
    1
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: 61661
    
  67

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: 1479
    
    1
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: 61661
    
  67

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

    Joined: Nov 16, 2004
    Posts: 1479
        
        1
    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
    Bartender

    Joined: Aug 06, 2010
    Posts: 543
        
        4

    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 SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
    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

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: File is Not Displaying