日期:2014-05-19  浏览次数:20673 次

Spring 表单绑定的问题

就是配置JSP页面绑定部分代码:

  <spring:bind path="command.username">
  <td><spring:message code="login.page.username" /></td>
  <td><input type="text" name="${status.expression }"
  value="${status.value }" /> <font color="red">${status.errorMessage}</font></td>
  </spring:bind>


错误信息:Neither BindingResult nor plain target object for bean name 'command' availa!

好像就是上面红包部分的那个command有什么问题?有没人告诉我这个command到底是什么东东?

waiting on line!



------解决方案--------------------
spring tag 没有用过,不过帮你查了下。内容如下:

<spring:bind>的"path"屬性設定了要綁定的表單物件名稱,這個名稱是設定在loginController 中的 "commandName"屬性,預設名稱是"command",當設定為"command.*"時,表示綁定表單物件上所有相關的數據, "status"的"errorMessage"會顯示在Controller中設定的錯誤訊息,這待會在Controller的實作中會再看到說明。

在表單中,對於"username"欄位,綁定了"command.username"屬性,"status"的"expression"會顯示綁定的屬性名稱,而"value"則顯示表單物件中所儲存的值,這邊設計的程式在登入失敗後會回到form.jsp,這樣可以在同一個頁面上顯示錯誤訊息與之前輸入錯誤的值。
------解决方案--------------------
那个错误的意思 应该是说: 你的form中没有叫做 command 的对象
------解决方案--------------------
作用域中必须放入一个类似的actionform的实体bean。