栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

BindingResult和普通目标对象都没有...异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

BindingResult和普通目标对象都没有...异常

当您在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");}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516346.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号