在foreach中提交表单

时间:2014-01-09 12:28:27

标签: forms jsp foreach

我有一个与一些servlet相关的jsp的servlet webapplication,其中,我有这样的形式:

<form action="MeetingDetails" method="post">
    <input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
    <c:forEach items="${comments}" var="comment" varStatus="i">
    <p><input type="hidden" name="cmtid" value="${comment.getKey()}"/>
    <c:out value="${comment.getKey()}"/> - <c:out value="${comment.getValue()}"/>
    <input id="minus" type="submit" name="action" value="DeleteComment"/></p>
    </c:forEach>
    <p>New Comment: <input type="text" name="cmt" value=""> <input id="plus" type="submit" name="action" value="AddComment"/></p>
</form>

当我发送动作时:删除到servlet,它会收到错误的“cmtid”值,如果我把表单放在foreach中,参数“mtgid”值为null ...

有没有这样做?

谢谢。

1 个答案:

答案 0 :(得分:0)

抱歉不方便,我想通了:

                            <c:forEach items="${comments}" var="comment" varStatus="i">
                                <form action="MeetingDetails" method="post">
                                <input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
                                    <p><input type="hidden" name="cmtid" value="${comment.getKey()}"/>
                                    <c:out value="${comment.getKey()}"/> - <c:out value="${comment.getValue()}"/>
                                    <input id="minus" type="submit" name="action" value="DeleteComment"/></p>
                                </form>
                                </c:forEach>
                                <form action="MeetingDetails" method="post">
                                <input type="hidden" name="mtgid" value="${selectMeeting.id}"/>
                                <p>New Comment: <input type="text" name="cmt" value=""> <input id="plus" type="submit" name="action" value="AddComment"/></p>
                                </form>

我有点混淆,没看到它