Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在forEach语句中区分多个输入表单_Html_Jsp_Jstl - Fatal编程技术网

Html 在forEach语句中区分多个输入表单

Html 在forEach语句中区分多个输入表单,html,jsp,jstl,Html,Jsp,Jstl,我有一个字符串数组,长度是可变的。我需要为每个字符串创建两个按钮:购买和删除。它们管理对应元素的数量。这样地: . 我试过这个,但不清楚 String go = request.getParameter("go"); if ((go != null)){ String[] info = go.split(","); int index = Integer.parseInt(info[1]); if (info[0].equals("

我有一个字符串数组,长度是可变的。我需要为每个字符串创建两个按钮:购买删除。它们管理对应元素的数量。这样地: . 我试过这个,但不清楚

String go = request.getParameter("go");
if ((go != null)){
    String[] info = go.split(",");
    int index = Integer.parseInt(info[1]);
if (info[0].equals("+")) {
    ++quantita[index];
} else {
    --quantita[index];
}}



使用
而不是
。此HTML元素允许您通过子元素而不是通过
value
属性设置内容。这样,您可以简单地使用
name
属性来指示操作,使用
value
属性来指示标识符

<button type=submit name="decrease" value="${i}">-</button>
<button type=submit name="increase" value="${i}">+</button>

这更清楚吗?

所以您需要其他方法来执行上述操作?是的,我使用了一种策略来解决问题,但代码不清楚。我需要用一个输入表单传递多个参数:id和act。我尝试使用隐藏的输入表单,但我不知道如何将其放入forEach中而不发生冲突。尝试使用
以便在循环下有多个标签,然后将按钮和表单放入其中。例如:
//您的循环//按钮和表单//循环关闭
<button type=submit name="decrease" value="${i}">-</button>
<button type=submit name="increase" value="${i}">+</button>
String decrease = request.getParameter("decrease");
String increase = request.getParameter("increase");

if (decrease != null) {
    --quantity[Integer.parseInt(decrease)];
}
else if (increase != null) {
    ++quantity[Integer.parseInt(increase)];
}