An interesting question:server-pushed response in servlet?

Discussions

Web tier: servlets, JSP, Web frameworks: An interesting question:server-pushed response in servlet?

  1. I don't know how to clearly describe the question.But I think it's interesting and hope some one to discuss on this topic.

    We face a problem,that is,we need a quick response while the web client request,and after the real logic is done on the server,another response should generated to the web client.So we need a server-push response.How to reach that requirement?

    I have tried using another thread to process the real logic but failed.Detailed as follow:
    1.new a thread to process the logic,and pass HttpRequest and HttpResponse as parameter to the thread
    2.while logic process is done,use RequestDispatcher to forward to the new specified URL

    But the result shows we could not take care of the HttpRequest and HttpResponse object which is owned by the container

    Who has good ideas?


  2. The problem you have here is that HTTP requests have to be initiated by the client. You cannot have an HTTP request initiated by the server.

    Consider a solution something like this:
    Create a HTTPSession that will last at least the duration of the processing. When the initial request arrives from the client allocate a thread to it and associate that thread with the HTTPSession in some way. Send a response back to the client immediately.

    The response you send back should include a delayed client-side redirect. The client will, after a little time, call another servlet. This second servlet will check the thread associated with the HTTPSession an determine whether processing is complete.
    If processing is not complete the servlet sends back the page with the client-side redirect. If processing is complete it sends the results.
  3. Thanks.Yes,it's feasible.We finally sovle the problem by employing the same way as yours.