Java 相当于 PHP 数组 POST 数据


Java equivalent of PHP array POST data

在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;
}