views:

27

answers:

1

Hi,

I'm trying to achieve the following behavior using the Servlet 3.0 API:

  • send an inital html page
  • send subsequent responses that update the page

This all works except the only way I could send the initial page without getting the response committed is by manually writing using the HttpResponse Writer...

I was wondering if there is a way of using something similar to RequestDispatcher#include with an html page without running into problems with the AsyncContext. Some things I tried until now and didn't work:

  • use AsyncContext#dispatch: as much as I read on the Internet, it is destined for sending the final response to the container in order to render it
  • use RequestDispatcher#forward: getting IllegalStateException due to trying to write more content in the OutputStream
  • use RequestDispatcher#include: if I initialize the AsyncContext before calling this method, request.isAsyncSupported returns true, after calling the method, it returns false. I read that it calls flushBuffer() and sets the commit flag to true on the response

Also, in the Servlet 3.0 spec there are some lines mentioning that dispatching from async servlet to normal servlet is possible but will commit the answer. I believe a static html page belongs to this category...

If you have any ideas of how an elegant include can be done without affecting the ability to still send streamed responses back to the client, please let me know.

Thanks

A: 

One solution (not the only one): if it's just a html page, then write the html page itself in html and do ajax calls to the serrvlet that needs to provide the updates.

Redlab
Thanks for the answer. I'm trying to use exclusively the Servlet 3.0 API to achieve server push. So, I can send only async responses. This would be one call to the servlet and the servlet would return multiple responses (this being achieved by not commiting the response, just flushing it).
MelmanRo
I have not played with the async api yet. But there is https://atmosphere.dev.java.net/ comet implementation! maybe it's worth a look
Redlab