当您在logincontroller中显示showAllComments.jsp时,您需要添加一个表单bean类(即Comment)作为模型的属性。
@RequestMapping(value = "/log_in", method = RequestMethod.POST)public ModelAndView tryToLogin(@RequestParam("uName") String uName, @RequestParam("pW") String pW, HttpServletResponse response, HttpServletRequest request) { ModelAndView ret = new ModelAndView("login", "command", new User()); User user = userService.existingUser(uName, pW); loggedInUser = new User(); model.addAttribute("command", new Comment()); if (user != null) { Map<String, Object> model = new HashMap<String, Object>(); model.put("COMMENTS", allComments); model.put("LOGGED_IN_USER", loggedInUser); ret = ModelAndView("showAllComments", model); } return ret;}
这应该工作正常。
更新
使用“命令”作为命令对象名称不是一个好习惯。对于班级注释,您可以使用“注释”或类似的内容。如果这样做,请使用以下代码更新表单。
<form:form method="post" action="postNewComment.html" commandName="comment"> <table> <tr> <td><form:label path="comment"> COMMENT </form:label></td> <td><form:input path="comment" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="WRITE" /></td> </tr> </table></form:form>
在所有其他地方进行相同的更改,即
model.addAttribute("comment", new Comment());
和
@ModelAttribute("comment")
更新2
@RequestMapping(value="userRegistration", method = RequestMethod.GET)public ModelAndView showUserRegistrationForm(Model model){ model.addAttribute("user", new AccountDetailsForm()); return new ModelAndView("userRegistration");}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)