1.需要使用validate方法
validate 方法繼承 actionsupport類
2 驗證錯誤結果需要在本類的this.addFieldError(驗證參數,傳遞數據);
this.addFieldError("username", "user can not be null");
3.struts.xml中 需要由input是struts2專門驗證的參數必須這么寫,是內部繼承的與
this.addFieldError關聯<result name="input">/index.jsp</result>跳轉到結果錯誤提示視圖
<action name="manage_*" class="cn.itcast.action.PersonAction" method="{1}">
<!-- 錯誤輸出時候會調用系統自帶的input視圖 -->
<result name="input">/index.jsp</result>
<result name="message">/WEB-INF/page/message.jsp</result>
</action>
4驗證結果輸出jsp頁面需要導入
<%@taglib uri="/struts-tags" prefix="s"%>
sturts2標簽,<s:fielderror/>
為輸出結果
“user can not be null”