Html JSP表中的按钮
我有一个带有表的JSP页面:Html JSP表中的按钮,html,jsp,servlets,Html,Jsp,Servlets,我有一个带有表的JSP页面: <table class="table table-hover"> <tbody> <thead class="thead-light"> <th scope="col">#</th> <th scope="col">Number</th> <th scope="col">Tariff</th> <th s
<table class="table table-hover">
<tbody>
<thead class="thead-light">
<th scope="col">#</th>
<th scope="col">Number</th>
<th scope="col">Tariff</th>
<th scope="col">Cost</th>
<th scope="col">Action</th>
</thead>
<tbody>
<c:forEach items="${contractsList}" var="contract" varStatus="loop">
<thead>
<th scope="col">${loop.index + 1}</th>
<th>${contract.number}</th>
<th>${contract.tariffName}</th>
<th>TODO</th>
<th><input type="submit" value="Block"></th>
</thead>
</c:forEach>
</tbody>
</table>
#
数
关税
成本
行动
${loop.index+1}
${contract.number}
${contract.tariffName}
待办事项
如何使每行中的按钮使用此行中的数据发送POST请求?例如,我按下第#2行中的一个按钮,它将post请求发送到某个url,并将此行中的合同号作为请求参数。我尝试添加
标记,但它破坏了表的格式,对于我来说,在这种情况下,不清楚如何将合同号作为请求参数传递
更新:我是这样做的
<tr onclick="showContract('${contract.contractId}')" style="cursor: pointer;">
<script>
function showContract(id) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = '/client/show_contract';
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'contractId';
input.value = id;
form.appendChild(input);
form.submit();
}
</script>
功能显示合同(id){
var form=document.createElement('form');
文件.正文.附件(表格);
form.method='post';
form.action='/client/show_contract';
var input=document.createElement('input');
input.type='hidden';
input.name='construcd';
input.value=id;
表单。追加子项(输入);
表单提交();
}
最简单的方法是将表单标记放入循环中
<c:forEach items="${contractsList}" var="contract" varStatus="loop">
<form action="..YourServlet" method="post">
<thead>
<th scope="col">${loop.index + 1}</th>
<th>${contract.number}</th>
<th>${contract.tariffName}</th>
<th>TODO</th>
<th><input type="submit" value="Block"></th>
</thead>
<input type="hidden" name="cnumber" value="${contract.number}"/>
<input type="hidden" name="ctarrif" value="${contract.tarrifName}"/>
</form>
</c:forEach>
String contractNumber = request.getParameter ("cname");
String tarrifName = request.getParameter ("ctarrif");