表单嵌套 - JSP、HTML
所以最近几天我一直在阅读有关 JSP 和 HTML 的内容。我读到 HTML 中不可能有嵌套表单。
有谁知道如何执行此操作吗?是否有一些 JSP 代码可以帮助解决这个问题?我的JSP/Java书中没有这样的东西。
请参阅我有一个表单,其中有用户可以动态添加或删除的元素 - 包括新表单。所以你可以把它看作一个层次结构 - 我有一个父表单,有 X 个(用户定义的)子级,每个子级可以有 Y(用户定义的)子级..等等 因此,当提交表单时,它会在该表单内创建一个新表单 - 然后,当提交最外层表单时,表单和子表单的所有详细信息都会复合到一个报告中(我还没有决定要做什么此信息)。所有这些信息都是特定于位置的,因此嵌套是强制性的。
我已经制作了一个 hack,带有全局变量和一些 javascript - 但它很容易受到攻击,并且当添加“用户”概念时,很可能会破坏会话等。所以我根本不想使用它,因为调试起来会很痛苦。
谢谢, U。
So I have been reading for the last few days on JSP and HTML. I read that it is not possible to have nested forms in HTML.
Does anyone have any indication of how to do this? Is there some JSP code that can aid in this? There is no such thing in my JSP/Java book.
See I have a form, to which there are elements that the user can dynamically add or delete - including new forms. So you can think of it as a hierarchy - I have a parent form, with X (user defined) children, each child can have Y (user defined) children..etc
So when a form is submitted, it creates a new form inside this form - then when the outer most form is submitted, all the details of the forms and subforms are then compounded into a report (I havent decided what I am going to do with this information). All this information is location specific, so the nesting is mandatory.
I have produced a hack, with global variables and some javascript - but it is vulnerable, and most likely will break when the concept of 'users' are added, with sessions etc. So I do not want to use this at all, given that it will be painful to debug.
Thanks,
U.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的第一个陈述是正确的;不能在 HTML 中嵌套表单。
如果您编写看起来像具有嵌套表单的 HTML 的内容,您可能会发现浏览器之间的行为有所不同。有些可能会在第一个
块之后切断表单字段,有些可能会提交所有字段元素,有些可能会按您的预期工作。
如果您的数据本质上是分层的,正如您的帖子所建议的那样,那么我可能会处理它的方式是拥有一个带有许多
的不过,您需要确保您的字段名称是唯一命名的 - 例如通过某种分层命名方案 - 例如
Your first statement is right; you can't nest forms in HTML.
If you write something that looks like HTML with nested forms, you'll probably find that the behaviour differs between browsers. Some may cut off the form fields after the first
</form>
block, some may submit all the field elements, some may work as you expect.If you data is hierarchical in nature as your post suggests, then they way I would probably handle it is to have a single
<form>
element with many<submit>
buttons. You can then choose to only examine the form fields related to the button that the user clicked. e.g. if they click "Child 1", then your JSP just looks at the fields related to "Child 1".You'll need to make sure that your field names are uniquely named, though - e.g. by some sort of hierarchical naming scheme - e.g.
<input type="text" name="Parent_Child1_name">
读完你的描述后,我立即想到了 jQuery 和 JavaScript。您可以动态修改 DOM 以根据需要添加和删除 HTML 元素,而不是嵌套
After reading your description I immediately thought of jQuery and JavaScript. You could dynamically modify the DOM to add and remove HTML elements as needed rather than nesting
<form>
elements. I'd recommend giving that a try.