two (2) HTTP responses...?


General J2EE: two (2) HTTP responses...?

  1. two (2) HTTP responses...? (2 messages)

    Hi all,

    I need your help;

    I need my jsp page to return basically two (2) HTTP responses.

    1. regular HTML page.
    2. a file that user wants to download (it is send to user by response.getOutputStream(),
       response.addHeader(...) and so on).

    This is simplified, but it comes down to this.
    I've tried to find the answer online without success. I have a bad feeling
    that this cannot be done because servlet spec says about response.sendRedirect method:

    "If data has been written to the response buffer, but not returned to the client
    (i.e. the response is not committed), the data in the response buffer must be
    cleared and replaced with the data set by these methods. If the response is
    committed, these methods must throw an IllegalStateException."

    Similar thing is said about the RequestDispatcher.forward method.

    But I am paranoid and hopeful enough to think that I am misunderstanding it.

    The only solution that I have is that upon processing the page there is
    a javascript which issues a download request.

    Any help or hint or .... will be appriciated


    Threaded Messages (2)

  2. one on one[ Go to top ]


    unfortunately for you: HTTP is a one request one response thing. I guess you want the user to click on a link to download a file, send him a confirmation page and the file itself. The only way to do this is what you already said:

    1. Send him the page.
    2. Tell the browser to download the file. You can do this either with JavaScript or with <meta http-equiv="refresh" content="1;url=[the url of the file to download]">

  3. two (2) HTTP responses...?[ Go to top ]

    I'd personally go for solution proposed by previous poster. I can't however rule out a different solution may exist. Some HTTP guru once told me that MIME-multipart thingy is a valid content type for a response. Whether popular browsers accept it is an entirely different matter though.
    I suspect that generating such a response may not be trivial either using servlets and JSP.

    Anyone tried this?