如何从 Java servlet 访问 HTML 表单名称?
我面临一个问题,单个 java servlet 需要处理多个 HTML 表单。因此,我想到在 HTML 中使用表单名称将其传递到服务器。
喜欢, 表格 1:
form method="POST" action='Controller' name="edit1"
表格 2:
form method="POST" action='Controller' name="edit2"
如何从单个 servlet 访问这两种表格?
I am facing an issue where a single java servlet needs to handle multiple HTML forms. So, I thought of using Form names in the HTML to pass it on to the server.
Like,
Form 1:
form method="POST" action='Controller' name="edit1"
Form 2:
form method="POST" action='Controller' name="edit2"
How can I access both these forms from a single servlet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提交时,表单名称不会随 HTTP 请求一起发送,因此不能在服务器端使用。
考虑在两种形式中添加具有相同名称但不同值的隐藏字段:
在您的 servlet 中:
Form name is not sent with the HTTP request on submit, thus it cannot be used on the server side.
Consider adding hidden field with the same name but different values in both forms:
And in your servlet:
基础知识:
按“提交”按钮提交相应的表格。
Basics:
Pressing Submit button with submit the respective form.