JSP/servlet/IE 组合不会在 Enter 上提交表单详细信息 [英] JSP / servlet / IE combination doesn't submit form detail on 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
但是,使用 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=提交
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屋!