JSP / servlet / IE组合不会在Enter上提交表单详细信息 [英] JSP / servlet / IE combination doesn't submit form detail on Enter

查看:103
本文介绍了JSP / servlet / IE组合不会在Enter上提交表单详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IE 7,JDK 1.6和Sun Web服务器7.

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

在jsp表单中,我们有:

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).

并且servlet具有:

and the servlet has:

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

使用 Fiddler 和IE,我们可以看到当我们填充id文本框并按Enter键时发送以下内容:

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


id = 123456

id=123456

然而,使用Fiddler和IE,我们可以看到在填充id时发送以下内容文本框并单击发送按钮:

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

userId=123456&send=Send

最终结果是有效地点击Enter键无效。

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

在其他jsp页面上,例如我们有:

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

<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit"/>

并且servlet具有:

and the servlet has:

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

使用Fiddler和IE,我们可以看到两种情况都发送了以下内容:

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


id = 123456& submitId = Submit

id=123456&submitId=Submit

所以它在我们看来,这种行为仅在IE上展示,其中提交按钮未被称为提交?

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

重新运行Firefox 3.6上的测试显示行为是正确的,两种情况都是一样的。

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

任何让IE正常工作的建议吗?

Any suggestions for getting IE to work correctly?

(注意:我搜索过类似的问题,但与此相关的问题主要与ASP有关!)。

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

推荐答案

对于只有一个输入字段的表单,这确实是另一个IE异常。唯一可行的解​​决方法是添加第二个输入字段(!)。您可以使用CSS隐藏它。不, type =hidden无效。

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"/>

这篇关于JSP / servlet / IE组合不会在Enter上提交表单详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆