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