###前提・実現したいこと
SpringMVCを使ってWEBアプリケーションを作っています。
ラジオボタンで選択した項目を、hiddenを使って渡したいです。
###Controller.java
@Controller public class Controller { @Autowired private JdbcTemplate jdbcTemplate; private static final String SELECT_SQL = "SELECT * FROM data WHERE id = "; @RequestMapping(value = "/index", method = RequestMethod.POST) public String vote(Model model, @RequestParam("id") int id) { StringBuilder sb = new StringBuilder(SELECT_SQL); sb.append(String.valueOf(id)); String sql = sb.toString(); List<Map<String, Object>> List = jdbcTemplate.queryForList(sql); model.addAttribute("tbl", List); return "index"; } @RequestMapping(value = "/top", method = RequestMethod.POST) public String top() { return "top"; }
###index.jsp
<f:form action="top" method="POST"> <table> <c:forEach var="column" items="${tbl}"> <tr> <th>名前</th> <td>${column.name}</td> </tr> <tr> <th>点数</th> <td> <c:set var="score" value="${column.score}" /> <c:forTokens items="${score}" delims="、" var="score"> <input type="radio" name="radio_button" value="${score}">${score} </c:forTokens> </td> </tr> <tr> <th>選択</th> <td> <input type="submit" value="確認"> <input type="hidden" name="score" value="${score}"> </td> </tr> </c:forEach> </table> </f:form>
以前、PHPを触ったときにもhiddenを使ったのですが、
値の受け渡し方法がphpとは違うと思うので質問をさせていただきました。
何卒よろしくおねがいします。
public String top() で何も値を受け取っていないようですが、フォームの値は受け取っているのでしょうか。
回答1件
あなたの回答
tips
プレビュー