开发者

JSP / servlet / IE combination doesn't submit form detail on Enter

开发者 https://www.devze.com 2022-12-22 04:21 出处:网络
Using IE 7, JDK 1.6 and Sun Web server 7. Inside the jsp form, we have: <input type=\"text\" name=\"id\" maxlength=\"20\" />

Using IE 7, JDK 1.6 and Sun Web server 7.

Inside the jsp form, we have:

<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="send" value="Send"/>

i.e. a text box and a "Submit" button (called Send).

and the servlet has:

if (request.getParameter("send") != null && request.getParameter("send").trim().length() > 0) { ... }

Using Fiddler and IE, we can see that the following is sent when we populate the id text box and hit Enter:

id=123456

However, using Fiddler and IE, we can see that the following is sent when we populate the id text box and click the Send button:

userId=123456&send=Send

The end result is that hitting the Enter key effectively does nothing.

On other jsp pages, e.g. we have:

<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit开发者_开发问答"/>

and the servlet has:

if (request.getParameter("submitId") != null && request.getParameter("submitId").trim().length() > 0) { ... }

Using Fiddler and IE, we can see that the following is sent for both cases:

id=123456&submitId=Submit

So it seems to us that the behaviour is only exhibited on IE for forms where the "Submit" button is not called "Submit"?

Re-running the tests on Firefox 3.6 shows that the behaviour is correct and the same for both cases.

Any suggestions for getting IE to work correctly?

(Note: I have searched SO for a similar problem but the questions relating to this mainly all ASP related!).


This is indeed another IE anomaly in case of forms with only one input field. The only solid workaround for this is to add a second input field(!). You can hide it using CSS. No, type="hidden" ain't going to work.

<input type="text" name="id" maxlength="20" />
<input type="text" style="display: none;" />
<input type="submit" name="send" value="Send"/>


Why are you checking for request.getParameter("submitId") in your JSP when in fact submitId is the name of your submit button?

In my experience I never had to check the value for the submit button. I only used that button to trigger the form submit and would usually only be interested in retrieving the values for the other form parameters.

If you want to differentiate the submit methods by the name of the submit button, you might want to try adding a "hidden" property using input type="hidden".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号