spring MVC做form提交Neither BindingResult nor plain target object for bean name 'command' available

這兩天在做spring3.0 MVC+hibernate3.2的練習中,做簡單的form提交,
一直報java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
查了好多資料都沒有辦法解決(有可能是報的錯誤一樣卻引起的原因不一樣吧),最後還是發現自己在jsp的form標籤上寫少了commandName屬性,
後來加上就可以了。
報錯時的代碼:<form:form method="post" action="addContact.html">
修正後的代碼:<form:form method="post" action="addContact.html" commandName="contact">

Spring給我們提供了一個commandName屬性,我們可以通過該屬性來指定我們將使用Model中的哪個屬性作爲form需要綁定的command對象。
除了commandName屬性外,指定modelAttribute屬性也可以達到相同的效果。 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章