#jspから取得した値
表の各行に設置したボタンから、押下された行の値を取得したいが、すべての行の値を結合された値がpostされてしまいます。(下記「Controller」を参照)
#実現したいこと
下記の表でcollectNoが2の行のボタンが押下された場合、postされるcollectNoを「2」としたい。
#jsp
html
1// 2// 3<form action="${pageContext.servletContext.contextPath }/aaa/bbb/ccc.html" method="POST"> 4 <table> 5 <tr> 6 <th>collectNo</th> 7 <th>aaa</th> 8 <th>bbb</th> 9 <th>ccc</th> 10 <th>削除</th> 11 </tr> 12 <c:forEach var="target" items="${List}"> 13 <tr> 14 <td class="centering">${target.collectNo}</td> 15 <td class="centering">${target.aaa}</td> 16 <td class="centering">${target.bbb}</td> 17 <td class="centering">${target.ccc}</td> 18 <td class="centering"> 19 <button type="submit" name="delete">削除ボタン</td> 20 //削除を押した行のcollectNoをpostしたい 21 <input type="hidden" name="collectNo" value="${target.collectNo}" /> 22 <input type="hidden" name="Num" value="${Num}" /> 23 </td> 24 </tr> 25 </c:forEach> 26 </table> 27</form> 28//
#出力されたテーブルが以下
collectNo | aaa | bbb | ccc | 削除 |
---|---|---|---|---|
1 | a1 | b1 | c1 | 削除ボタン |
2 | a2 | b2 | c2 | 削除ボタン |
3 | a3 | b3 | c3 | 削除ボタン |
4 | a4 | b4 | c4 | 削除ボタン |
5 | a5 | b5 | c5 | 削除ボタン |
#Controller
java
1 @RequestMapping(value = "/aaa/bbb/ccc", params = "delete", method = RequestMethod.POST) 2 public String jumpToDelete(@RequestParam(required = false) String collectNo, @RequestParam int Num, 3 RedirectAttributes attributes) { 4 5 System.out.println(collectNo);//「"0,1,2,3,4,5"」が出力される 6 }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。