/FormTest/src/org/fkit/controller/UserController.java
@RequestMapping(value="radioform1" ,method=RequestMethod.GET) public String radioForm1(Model model) { User user = new User(); user.setSex("男"); model.addAttribute("user",user); List<String> sexList = new ArrayList<String>(); sexList.add("男"); sexList.add("女"); model.addAttribute("sexList", sexList); return "content/radioForm1.jsp"; }
/FormTest/WebContent/content/radioForm1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>radiobuttons</title> </head> <body> <form:form modelAttribute="user" method="post" action=""> <table> <tr> <td>性别:</td> <td> <form:radiobuttons path="sex" items="${sexList}"/> </td> </tr> </table> </form:form> </body> </html>
测试结果: