Spring-MVC:JSP 视图发送一系列值到控制器,而不是单击按钮的一个值

问题描述 投票:0回答:1
<form name="update" id="update" action="update" method="post">
<table border="0">
<tr>
<th></th>
<th>Del</th>
<th>Name</th>
<th>Address</th>
<th>Remarks</th>
</tr>

<c:forEach items="${recList}" var="rec" varStatus="loop">
<tr>
<td><input type="checkbox" name="del" value="${loop.index}"/></td>
<td><input type="text" name="name" value="${rec.getName()}"/></td>
<td><input type="text" name="address" value="${rec.getAddress()}"/></td>
<td><input type="text" name="remarks" value="${rec.getRemarks()}"/></td>
<td><input type="hidden" name="index" value="${loop.index}"/>
<input type="submit" value="Update"/></td>
</tr>
</c:forEach>

</table>
</form>

这是此视图的代码

enter image description here

我的问题是,当我单击UPDATE按钮时,表单似乎发送了一系列值,例如

name= "aiko,hashimoto,yuki,ode"

而不是仅发送

name="hashimoto"

如果单击第二个UPDATE按钮,则为Controller。谁能帮我解决我的问题?<form>标签不能位于<table>中。从逻辑上讲,我认为最好将内部放入循环中,但这是不可能的。还有其他解决方法吗?

java spring spring-mvc jsp
1个回答
0
投票
    Submit your form with javascript function using ajax call like below sample code.
    send single value from form submit not possible 

    function submitform(){

         var messageId = $("#messageId").val();
        $.ajax({
            url:'<c:url value="/dummy/dummyMessageId"/>',
            datatype:'JSON',    
            data: 'messageId=' + messageId ,
            success : function(response) {
            if (null != response && response.success) {      
              } else {
                    var errorDiv = $('#Error');
                    errorDiv.html(response.error.message);
                    }
                }               
        });
    }
    <input type="button" value="Update" onclick="submitform()"/></td> 
   add above code  in your HTML input button
© www.soinside.com 2019 - 2024. All rights reserved.