Thread: response.write

    #1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    26
    Rep Power
    0

    Exclamation response.write


    Hi,

    I hv the fwg code that reads a blob from an Oracle db and outputs it.. the prob is that the output is shown in the same browser window or in some cases opens abruptly in another application (in my case it opened in Homesite!!)...

    Is there any way I can force the output to appear in a new browser window like a pop up??

    PHP Code:

          response
    .setContentType(contype);
        
    // response.setHeader("Content-Disposition", "attachment; filename=\"" + doccode + excel +"\"");
          
    long index 1;

          while(
    index doc.length()){
          
    response.getOutputStream().write(doc.getBytes(index,100));
           
    index+=100;

         } 
    Note, I am not setting the header as I dont want an save/open dialog box...

    Oh yes, one more thing.. sometimes on certain blobs, i get this error "java.lang.IllegalStateException: getOutputStream() has already been called for this response"
    Why does this happens??

    any suggestions??

    thnx,
    sgaucho
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, as for setting the header, if you don't set a content type the browser is going to assume text/html. You probably don't want that if you're sending back an xls file.

    As for a popup window, the best way would be to create the popup window *first*, and point it at your code.

    The odd window behavior is probably related to the content type not being text/html.

    As for the error, your while loop should look like
    Code:
    OutputStream out = response.getOutputStream();
    
    while(index < doc.length()) {
      out.write(doc.getBytes(index,100));
      index+=100;
    }
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    26
    Rep Power
    0
    Hi,

    I changed my code as per ur suggestion, but continue to get the "java.lang.IllegalStateException: getOutputStream() has already been called for this response" Error...

    AGain, this happens only on a few types of blobs.. whats strange is I hv 4 types of blobs.. word, an xls file, 1 text and 2 images... the code runs fine for all except for 1 image where it throws the above exception..

    any more suggestions??

    thnx again,
    sands
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    26
    Rep Power
    0
    solved it.. closed the outputStream and the problem disappeared...

IMN logo majestic logo threadwatch logo seochat tools logo