我不知道如何在struts config xml中沒有指定Validate = true的情況下執行struts 2驗證。你能告訴我使用驗證框架的Struts 2驗證流程嗎?Struts 2需要澄清
回答
通過組合"validation" and "workflow" interceptors進行驗證。 Struts 2配置文件中沒有「驗證」設置,因爲沒有必要。
如果你稍微解釋一下,我將不勝感激。我是struts 2的新手,我熟悉struts 1.2。 – user961532
[S2簡而言之](http://struts.apache.org/2.2.3.1/docs/nutshell.html)。 –
Struts核心具有驗證框架,可幫助應用程序在執行操作方法之前運行規則以執行驗證。
動作類作品作爲域數據,它看起來在其操作映射文件的屬性和它在theFileName-validation.xml中搜索字段驗證和所有驗證工作,按照在驗證定義的字段.XML。如果數據不匹配,它會從validation.xml中選擇消息並將其顯示給用戶。
樣品員工-validation.xml中:
<validators>
<field name="name">
<field-validator type="required">
<message>
The name is required.
</message>
</field-validator>
</field>
<field name="age">
<field-validator type="int">
<param name="min">29</param>
<param name="max">64</param>
<message>
Age must be in between 28 and 65
</message>
</field-validator>
</field>
</validators>
這是員工模型和請求樣本驗證文件的屬性名字和年齡將被驗證。如果名稱字段爲空,驗證會在名稱輸入框上方顯示錯誤消息爲「名稱是必需的」。如果輸入的年齡超出29-64的限制,驗證將顯示錯誤爲「年齡必須介於28到65「以上的年齡輸入框。
- 1. 需要澄清NSAutoreleasePool
- 2. ApplicationDomain澄清需要
- 3. 需要澄清UIApplicationState
- 4. ConcurrentModificationException,需要澄清
- 5. InsertHelper澄清需要
- 6. 需要澄清Datatable
- 7. drawAtPoint,澄清需要
- 8. previousLocationInView,澄清需要
- 9. NSFetchedResultsController:DOC澄清需要
- 10. rootViewController澄清需要
- 11. 需要澄清毒斑點
- 12. Angular2 - Keyup需要澄清
- 13. On UnsatisfiedLinkError,需要澄清
- 14. 需要澄清認識_.some()
- 15. 需要澄清SVN恢復
- 16. 錯誤C2664,需要澄清
- 17. IDEA項目,需要澄清
- 18. Objective-C,UITableView,需要澄清
- 19. ASP.NET TextBox:TextChanged - 需要澄清!
- 20. Objects.hash()VS Objects.hashCode(),澄清需要
- 21. 在NSRunLoop,澄清需要
- 22. Axis2/WSO2 ESB - 需要澄清
- 23. UINavigationController TitleView - 需要澄清
- 24. Angular 4 - * ngComponentOutlet澄清需要
- 25. 需要在C#旗澄清
- 26. 在ServerSocket的,需要澄清
- 27. Facebook/keytool澄清需要
- 28. 需要wso2is的概念澄清
- 29. 基本算法的書,澄清需要
- 30. 定位圖像,需要澄清
我正在使用struts.xml,通過定義一個擴展了「struts-default」的包來指定它。你需要知道攔截器是如何工作的,網上寫了很多,最好的開始是在struts2-core-xxxjar中打開struts-default.xml,你會看到「struts-default 「是被定義的,並且有很多攔截器堆棧,並且非常靠近」defaultStack「所在的底部,並且被設置爲默認值。搜索攔截器的名稱將使您瞭解已完成的工作,您可以利用這些工作。 – Quaternion