views:

351

answers:

3

My Servlet app. gets called twice every time the user submits a form: The first time with a POST request, and immediately after, with a GET request (both requests with the same URI).

This problem appears to be independent of the app server (I've tried with tomcat-6.0 and with resin.2.1).

The problem seems to be browser related: The problem does not occur with the MS Internet Explorer 6.0, 7.0 and 8.0 clients, but it does with Google Chrome-2.0 and with FireFox-3.0.11 clients.

The HTML code is trivial:

<form method="post" action="MyServlet?formSubmitted">
    <input type="text" name="data">
    <input type="submit" value="OK">
</form>

Could somebody explain such behaviour? Thanks in advance, Carlos

A: 

This looks very similar to this bug registered against Chrome. I would track this and find the resolution.

Brian Agnew
I stand corrected, at least with Chrome. Firefox, however, I'm not convinced (and don't see that behavior on FF 3.0.11 / Linux).
kdgregory
It's a pretty serious bug to have appeared in the (relatively) mature Firefox, granted
Brian Agnew
You are completely right. I do not blame these browsers.There must be something wrong in my code, and that's why I asked for help. Who knows if somebody had faced something similar in the past!.Thank you anyway, Carlos
Can you check the browsers again ? Your issue appears related to a known Chrome bug. But kdgregory isn't convinced re. Firefox. I would upgrade both
Brian Agnew
Chrome says it is up to date (2.0.172.33)<br>I'll check updating FireFox...<br><br>In the meanwhile, I followed the advice of kdgregory, and tried to simplify my test case, creating very basic code, able to be understood and reproduced by anybody, and...<br>The result is reasonable: I can't reproduce the problem. Chrome sends only one POST at form submit.
A: 

If you're convinced it isn't client-side JavaScript (and I appreciate that you took the time to simplify the test and verify), then the next thing I'd look for is a server-side redirect.

I believe that you're running on Windows (that's the only place Chrome exists, right?), so download the Fiddler tool (produced by MSDN). It will show you all the requests that happen between your client and server. If you see the POST getting a 302 response, that is an indication of a server-side redirect. monitoring

kdgregory
Thanks a lot, kdgregory. Fiddler is really enlightning.
I am a miserable ignorant, and I wouldn't like to bore you with my partial progress reports, but I feel compelled to write them. Maybe this helps me in the path to the solution.
Firs of all, I have updated to FireFox-3.5 and the problem disappears: only one POST per user interaction on a form submit.
Second, an inspection with Fiddler produces different output for the different browsers:
FireFox-3.5 has the expected behaviour: One POST request, followed by different GET requests for the static resources of the returned page (images and CSS) All requests return with a code of 200(OK)
Chrome-2.0 produces one POST request and one GET request with exactly the same query string.
I forgot to mention that both requests result with a 200(OK) code
IE6 (I must use it because my customers still do) reveals also bad behaviour with Fiddler. I didn't have detected it before because the application does not complain: It produces one POST request to the right query string of my test case, and a GET request to a different query string: to the session's initial URL request !!!.Both are responded with a 200(OK)
FireFox-3.0.11 (similar to Chrome.2.0) produces one POST request followed by a GET request to exactly the same query string, both being responded with a 200(OK)
I got it! Matthew (see his answer below) was right!!!It was an image with empty src, that was fooling FireFox-3.0, Chrome, and (although differently) also IE6!.Thank you for your attention and for your help.
+2  A: 

I have just had exactly the same problem and it turned out to be an tag with an empty src parameter in the new page that is rendered, this caused Firefox to do a get that looks the same as the original post.

Thanks Matthew for your hint. I'll try to corroborate that in my case.
Definitely, this was also my case! An image tag with empty src !!!Thank you very much for your valuable help.
good catch - I recall seeing a slightly different question a few days ago regarding an empty URL, but never would have thought to look for it as a cause
kdgregory
(and not sure why you flagged as wiki -- that answer deserves points)
kdgregory