掃二維碼與項目經理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯網交流
Struts validate驗證

成都創(chuàng)新互聯公司成都網站建設按需網站建設,是成都網站建設公司,為地磅秤提供網站建設服務,有成熟的網站定制合作流程,提供網站定制設計服務:原型圖制作、網站創(chuàng)意設計、前端HTML5制作、后臺程序開發(fā)等。成都網站改版熱線:18982081108
1. ActionErrors和ActionError都是ActionMessages的子類,ActionError存放在ActionErrors 中,ActionError對象中的參數為配置文件中配置的相應的值,若配置文件中沒有配置或配置文件不適合都不能用 < htnl:errors property=""/>輸出。
2.錯誤信息添加用
ActionErrors errors=new ActionErrors();
errors.add("error_key",new ActionError("配置文件中的相應的值"))
注解:void add(java.lang.String property,ActionError error)
在jsp頁面中顯示錯誤:
3.在Action中使用ActionMessages 他有兩個add方法:
他有兩個add方法:
void add(ActionMessages message) |
錯誤信息添加使用errors.add("error_key",new ActionMessage("errors.loginerror"))
另外要調用this.saveMessages(request,errors)方法;
這是org.apache.structs.action.Action中 的方法,要用到的大概有兩個:
1.saveErrors(少用)
protected void saveErrors(java.servlet,http.HttoServletRequest request,ActionErrors errors)
Save the specifiled error message keys into the appropriate request attribute for use by the
tag,if any message are required.Otherwise,ensure that the request attribute is not created.
2.saveMessage(常用)
protect void saveMessage(javax.Servlet.http.HttpServletRequest request,ActionMessages messages)
Save the specified message keys into the appropriate request attribute for use by the
if messages="true" is set},if any message are required,Otherwise,ensure that the request attribute is not
created.
ActionErrors actionMessages ,ActionMessage ActionMessage是繼承關系,父類在前,子類在后
if (!loadForm.getUsername().equals("123")) {
|
FORM里面
public ActionErrors validate(ActionMapping mapping, |
【編輯推薦】

我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯網交流