----- Original Message -----
From: "Bo Xu" <[EMAIL PROTECTED]>
> * I hava a question: how to detect the "HTTP connecting status"
> in Servlet-side, I suspect that I can split it into 3 parts:
> -1 how to detect it when Servlet is receiving requesting from client
I don't think that the servlet (I refer to the class extending HttpServlet)
receives the request. It is the container which receives the request. Also
the request might have been received by a web server and then forwarded to
the container.
Why do you need to know this?
> -2 how to detect it when Servlet has already got all requesting,
> but doesn't begin to response
If it is a GET request, the moment your servlet is invoked it means that the
request has been received in totality.
Things get complicated if you are talking of a POST request. Underlying all
HTTP requests it a socket connection/communication.
But in a servlet you never get to see the InputStream from the socket as the
best you get is a ServletInputStream. This hides the handling of the
Socket's InputStream from the servlet. The container is then free to
implement the functionality in the manner that it wants. It might buffer the
request or might employsome other practice. I think one can be sure that the
whole request has been received if the input stream has been fully read
(i.e. the ServletInputStream can offer no more input)
[snipped]
> - the question is: how can MyServlet know that the client is still there
> or already leave? for example, I suppose that if MyServlet knows
> the client has already leave, MyServlet can stop the database
searching
There is no reliable way to do this.
See below.
>
> * yesterday there are several emails in TOMCAT-USER Listwhich intrduces
> to use ServletResponse.flushBuffer() which is in Servlet APIspec2.2+,
> i.e., trying to detect the connection status by catching the
IOException of
>
> flushBuffer().
>
> * my questions are:
> - does the above sulotion work? does it work for both the following:
> % Servlet-container only
> % WEB-server(for example, Apache) + Servlet-container
The flushBuffer method was suggested on the tomcat user list [1] and also
many times on this list.
This method is not fool proof. The reason for this is if the user cancels
the request, the browser closes the socket which it establishes.
Now closing of this socket does not guarantee that the flushBuffer will
generate an exception. There might be a lot of buffering going on between
the servlets output and the browser (proxies, web servers, servlet
containers) which can prevent the generation of the exception.
Another issue which I am not sure of is if the vesion 1.1 of HTTP is being
used. I have a feeling that another request or pressing of the stop button
may not lead to the closing of the socket connection, but I am not sure.
Maybe someone here can clarify this.
> % if the buffer is already empty, can it work? i.e., can " a
method in
> a class which extends OutputStream" throw(s) a IOException when
> In Fact it doesn't output bytes? otherwise, if I don't have
data in
> the
> buffer, I will not be able to detect the connection status.
If there is nothing in the buffer, flushBuffer() should not try to write to
socket and so there will not be any exception being generated.
> - is it possible to use "java.io.InputStream.available()" in
Servlet-side to
> detect the connection status?
As mentioned above, the servlets see only the
javax.servlet.ServletInputStream whose available in now way corresponds to
the status of the underlying socket.
> - is there other way to detect the connection status?
I think there is no way to do this. I would love to hear of a fool proof way
to do this, if there is one.
One of the suggestions given on this list earlier was that if it is known
before hand that the output/processing might take time then it is better to
warn the client about the delay and use client pull to get the results..
Regds,
Gokul
>
> Bo
> June 21, 2001
[1] Some of these posting are visible in the search at the following url
with the subject "flushing"
http://mikal.org/interests/java/tomcat/archive/search?search=flushing
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html