Problem with servlet "respoonse"

M

mh

hi everyone,

this problem has been driving me crazy for days... I have built a
servlet that takes some simple parameters, performs some calculations
and then writes a HttpServletResponse response back to the client. The
code works *some* of the time - which sounds unusual, but the problem
is sometimes a HttpServletResponse is not sent back. The request always
reaches the server, and calculations are always carried out; similarly
the method to write the response is always called successfully. By
using some system out statements, I have noticed that:

- when the response is sent (XML, I'm using Ajax techniques)
successfully, the .isCommitted() method when evaluated in the doGet is
always true. When no response is sent, the same evaluates as false.

- using the response.toString() method, I got output such as:

org.apache.catalina.connector.ResponseFacade@ea85b4 or sometimes
org.apache.catalina.connector.ResponseFacade@627b5c

as a typical response. I sit there and click send several times to see
what happens, and I've noticed that responses are NEVER sent when
subsequent responses have different memory addresses (e.g. @627b5c and
@ea85b4). Subsequent (relatively close together in time) submits all
work because - as mentioned - they have the same memory address.

I have purposely not included code because the code does work - in the
sense that it quite easily can form and send a response. I've read a
fair bit of material and am totally stumped on this. Is this a problem
with establishing/committing a response??

Thanks!
Matt
 
A

adamspe

have you explicitly called flushBuffer() on the response? Seems like
it shouldn't be necessary once your servlet has finished the associated
"do" method but seems it could be possible that the sometimes
working/sometimes not -could- be associated with whether or not the
default buffer size is being reached or not. Seems unlikely though,
just a thought.
 
J

John C. Bollinger

mh said:
this problem has been driving me crazy for days... I have built a
servlet that takes some simple parameters, performs some calculations
and then writes a HttpServletResponse response back to the client. The

A more conventional way of saying this would be that the servlet sends
an HTTP response to the client via the HttpServletResponse object. The
HttpServletResponse is a server-side object for controlling the
servlet's HTTP response to the client's HTTP request; the
HttpServletResponse object itself is not transmitted to the client.
Yes, this is a bit nit picky, but it very much helps to be as clear as
possible about the details, especially when something you can't explain
is happening.
code works *some* of the time - which sounds unusual, but the problem
is sometimes a HttpServletResponse is not sent back. The request always
reaches the server, and calculations are always carried out; similarly
the method to write the response is always called successfully. By
using some system out statements, I have noticed that:

- when the response is sent (XML, I'm using Ajax techniques)
successfully,

I suppose you mean "when the client receives the response [...]".
the .isCommitted() method when evaluated in the doGet is
always true. When no response is sent, the same evaluates as false.

That seems consistent with your general observation that the client did
not receive a response in those cases.
- using the response.toString() method, I got output such as:

org.apache.catalina.connector.ResponseFacade@ea85b4 or sometimes
org.apache.catalina.connector.ResponseFacade@627b5c

as a typical response.

Which means almost nothing.
I sit there and click send several times to see
what happens, and I've noticed that responses are NEVER sent when
subsequent responses have different memory addresses (e.g. @627b5c and
@ea85b4). Subsequent (relatively close together in time) submits all
work because - as mentioned - they have the same memory address.

You should not assume that the "@[...]" represents a memory address, but
you can be confident that seeing the two different string values does
indicate two distinct response objects. As I understand it, Tomcat does
cache and reuse request and response objects.
I have purposely not included code because the code does work - in the
sense that it quite easily can form and send a response.

The same thing nevertheless applies here as if your code failed
reliably; it is exceedingly hard to diagnose the problem without looking
at the code. I will try to offer some general suggestions, however (below).
I've read a
fair bit of material and am totally stumped on this. Is this a problem
with establishing/committing a response??

I am not aware of any general problem with Tomcat in this regard. (This
is container-specific, but I recognize Tomcat package names in your
response string values above.) Much more likely would be a problem in
your servlet's code, and my bet would be on one of these things:

1) Your servlet is not thread safe, or
2) Your servlet is holding on to a reference to the response and/or
request object past the end of processing the request (as marked by
return from doGet() / doPost().

The latter of those might take the form of storing the response object
in a static or instance variable in the servlet, or directly or
indirectly in a session or context attribute (ouch!).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top