在PHP中我可以做以下事情
<input type="text" name="title[]" value="val1" />
<input type="text" name="title[]" value="val2" />
Java 中的 name="title[]"
是什么?
或者我和我的团队可以做些什么来做同样的事情?
最佳答案
Java 不会将 []
视为特殊字符。您可以使用以下代码段获取参数:
public static Map<String, String> getParameterMap(ServletRequest request, String mapName) {
Map<String, String> result = new HashMap<String, String>();
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.getNextElement();
if (name.startsWith(mapName + "[") && name.endsWith("]")) {
result.put(name.substring(mapName.length()+1, name.length() - 2), request.getParameter(name));
}
}
return result;
}
关于PHP 数组 POST 数据的 Java 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19135722/