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屬性也可以達到相同的效果。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM