Mandor
Mandor

Reputation: 3

How to figure out if javax.servlet successfully sends the response

I'm using a jetty server to handle http requests. I would like to know if there is any way I can check if the response is successfully sent back to the client. Is there an error code or status that I can check, or an exception I can catch if the transfer to the client failed for any reason?

Thanks

Upvotes: 0

Views: 861

Answers (1)

Stephen C
Stephen C

Reputation: 719249

Is there an error code or status that I can check, or an exception I can catch if the transfer to the client failed for any reason?

It sounds like you want the server to be able to know if the response was delivered completely to the client.

The simple answer is there isn't a way to know this. TCP/IP doesn't support this, HTTP does not support this, and the Servlet APIs don't support this.

In some circumstances, an exception may be throw if the server notices that the client has closed the connection early. But there are no guarantees that it will notice, or that it will result in an exception that will be visible to the application servlet code. Indeed it is quite likely that the close won't be noticed (if at all) until after the servlet call has returned.


If you want to implement some kind of "response delivered" acknowledgement for web pages, you could embed some "onload" Javascript in the webpage that sends an AJAX request back to the server. But then you have to consider the case where the user has disabled Javascript, or the original request was made by a non-browser application.

Upvotes: 2

Related Questions