English 中文(简体)
服务器边处理动态表格
原标题:Processing Dynamic forms on the Server Side

我在这里看到许多问题,涉及在 j库里或其他 j夫图书馆采用动态形式,我认为我设法为我的测试目的建立动态形式。

我的问题是,在把我的形式领域命名和在服务器方面处理它们方面的最佳做法是什么。

我试图实施一种类似形式的接触,即用户可以增加多种电话号码(和类型)以及多种地址(和类型),类似于以下代码,这是将动态重复的代码。

<div id="phones">
<label>Phone Number</label><input type="text" name="phone1" value="" />
<label>Type</label><input type="text" name="type1" value="" />
</div>

Then I will have a +/- link or button to add another phone or remove a phone. When I submit the form, whats the best way to handle the combo of name/type Should I have the names like indicated above with a postfix of an id like phone1 / type1 or should I use the array naming like phone[] / type[] and match the pairs on the server according to the index.

我正在使用java(如果是java 或 php,或者不管怎样),但这样做的最佳做法是什么。

增 编

最佳回答

带有指数的方括号似乎是大多数框架期望的,但完全取决于你的框架。 在 Java,鉴于约有100万个不同的框架,你必须从你们的框架中开始,并适当调整 Java法。

唯一熟悉答案的Java框架Im是加沙地带,它想要方括号。 贵爱者的财产

private List<Address> addresses;
public List<Address> getAddresses() { return addresses; }
public void setAddresses(final List<Addresses>) { this.addresses = addresses; }

然后,投入需要“地址[0].street1”、“地址[0].street2”等名称。 当你为新地址增加一个新的栏目时,你拥有相同的“1”而不是“0”。

然而,不同的 Java框架可能以完全不同的方式行事。

问题回答

在你看来,你应具体指出这个领域。 不要使用阵列点命名公约,它过去使我大头疼。

如果你使用阵列,如果参数缺失,你就会冒着错配类型和电话价值的风险。 一些浏览者根本无视空洞的价值观。

为了帮助服务器检索所有参数,我通常把田地数目放在一个隐蔽的领域。 表格将照此办理。

<div id="phones">
<input type-"hidden" name="count" value="3" />
<ul>

<li>
<label>Phone Number</label><input type="text" name="phone1" value="" />
<label>Type</label><input type="text" name="type1" value="" />
</li>
<li>
<label>Phone Number</label><input type="text" name="phone2" value="" />
<label>Type</label><input type="text" name="type2" value="" />
</li>
<li>
<label>Phone Number</label><input type="text" name="phone3" value="" />
<label>Type</label><input type="text" name="type3" value="" />
</li>
</ul>
</div>




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签