我有一个供用户输入小狗信息的jsp。
<FORM action="/publish" method="post" commandName="puppy" >
<table border=0 cellspacing=0 cellpadding="0">
<% String[] textFields = {"category", "name", "gender", "age", "price"};
for (int j= 0; j<textFields.length; j++){ %>
<tr> <td> <%=textFields[j]%>: </td>
<td> <input type=text name=<%=textFields[j]%>> </td>
</tr>
<% } %>
</table>
<input type = "submit" value="submit">
</FORM>
我有一个包含类别、名称、性别、年龄、价格的小狗对象。
在控制器中,我想获取用户写入的小狗信息
@RequestMapping(value = "/publish")
public String publish (@ModelAttribute("puppy") Puppy newP, BindingResult result){
System.out.println("Puppyname: " + newP.getName());
return "redirect:publish.jsp";
}
这不起作用。谢谢你的帮助!