如何将循环参数从JSP传递给Spring Controller

时间:2018-02-20 11:38:49

标签: spring jsp spring-boot

我在JSP页面上有一个循环,想要在Spring Controller中传递这些值。在JSP中的每次单击“重试”按钮时,我需要控制器中的所有值以进行进一步处理。我到目前为止尝试的代码是: 任何帮助非常感谢。

JSP文件

<table class="gridtable">
<tr>
    <th>Queue Name</th>
    <th>Retry Attempt</th>
    <th>Reason for failure</th>
    <th>Action</th>
</tr>
<% int i=0; %>
<c:forEach var="queueRowDetail" items="${queueRowDetailList}">
<tr>
    <td>${queueRowDetail.queueName}</td>
    <td>${queueRowDetail.attempt}</td>
    <td>${queueRowDetail.errorDetails}</td>
    <td>
        <form:form  method="post"  action="/retry" id="frmFailure_<%=i%>" modelAttribute="queueRowDetail"/>
            <form:hidden path="queueName<%=i %>" value="${queueRowDetail.queueName}"/>
            <form:hidden path="attempt<%=i %>" value="${queueRowDetail.attempt}"/>
            <form:hidden path="errorDetails<%=i %>" value="${queueRowDetail.errorDetails}   "/>

            <input type="button"  value="Retry" onClick="sendobj(<%=i%>)" />
        </form>
    </td>

</tr>
<%  i++; %>
</c:forEach> 

function sendObj()

<script>
    function sendobj(i)
    {
        var x = document.getElementById("frmFailure_"+i);
        alert(obj);
        alert("frmFailure_"+i);
        x.submit();// Form submission

    }
</script>

QueueRowDetail Class

package com.gartner.gqueuefailureapi.model;
public class QueueRowDetail {

private String queueName;
private String errorDetails;
private int attempt;
private Object payLoad;

public String getQueueName() {
    return queueName;
}
public void setQueueName(String queueName) {
    this.queueName = queueName;
}
public String getErrorDetails() {
    return errorDetails;
}
public void setErrorDetails(String errorDetails) {
    this.errorDetails = errorDetails;
}
public int getAttempt() {
    return attempt;
}
public void setAttempt(int attempt) {
    this.attempt = attempt;
}
public Object getPayLoad() {
    return payLoad;
}
public void setPayLoad(Object payLoad) {
    this.payLoad = payLoad;
}
}

InderController.Java

@RequestMapping(value = "/retry", method = RequestMethod.POST)
public String retryMessage( @ModelAttribute("queueRowDetail")QueueRowDetail queueRowDetail,  ModelMap model) {

    model.addAttribute("queuename", queueRowDetail.getQueueName());
    return "success";

}

0 个答案:

没有答案