成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Struts validate驗證的具體實現

開發 后端
本文將對Struts validate驗證進行講解,Struts validate驗證通過XML文件進行配置,希望本文對大家有所幫助。
Struts validate驗證

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)
  Adds the meesage from the given ActionMessage object  to tjis set of meesage
void add(java.lang.String property,ActionMessage message)
             Add message to the set of message for the specifiled property.

錯誤信息添加使用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<html:errors>
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<html:message>tag{
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")) {

   ActionMessages error = new ActionMessages();
   error.add("username", new ActionMessage("error.username"));
   saveErrors(request, error);

   return mapping.findForward("S1");
  }

  if (!loadForm.getPassword().equals("abc")) {

   ActionMessages error = new ActionMessages();
   error.add("password", new ActionMessage("error.password"));
   saveErrors(request, error);

   return mapping.findForward("S1");
  }

  return mapping.findForward("S1");

error.username=<font color="red">\u5e10\u53f7\u9519</font>
error.password=<font color="red">\u5bc6\u7801\u9519</font>
error.up=<font color="red">\u5e10\u53f7\u6216\u5bc6\u7801\u4e0d\u80fd\u7a7a</font>

FORM里面

public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {

  ActionErrors errors = new ActionErrors();
if (null == username.trim() || null == password.trim()||username.length()<3

||password.length()<2) {

   errors.add("username", new ActionMessage("error.up"));
   System.out.println(errors);

   return errors;
  }

  return null;
 }

native2ascii 來處理中文漢字

【編輯推薦】

  1. 在Eclipse中開發struts應用程序
  2. 手把手教你在Eclipse中配置開發Struts
  3. Eclipse下開發struts完整解決亂碼問題
  4. Struts相關背景介紹
  5. 使用Easy Struts for Eclipse開發Struts
責任編輯:張燕妮 來源: javaeye.com
相關推薦

2009-06-25 15:33:12

Struts2教程使用validate驗證數據

2009-02-04 12:00:08

2009-11-25 11:33:26

PHP驗證表單

2009-11-23 16:59:23

PHP圖形驗證碼

2009-06-04 10:33:10

struts vali框架

2011-03-30 09:03:57

struts2

2009-06-05 09:58:20

struts2驗證用戶注冊

2009-06-25 15:37:12

Struts2教程Validation框

2009-06-04 10:54:59

實戰strutsMenu

2011-04-28 09:52:04

Struts2

2009-06-05 09:52:25

struts分頁Hibernate

2010-07-22 13:23:46

telnet SMTP

2010-06-08 14:28:16

Opensuse中文

2009-02-04 13:13:03

2009-06-03 15:38:37

Struts框架RBAC

2009-07-20 16:51:59

Struts2.0+i

2009-11-23 18:39:17

PHP重定向

2010-06-08 15:02:39

Opensuse u盤

2010-07-13 10:38:54

2009-08-26 13:41:58

C#打印源碼
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 91精品国产欧美一区二区成人 | 在线观看亚洲专区 | 激情久久网 | 99这里只有精品视频 | 91精品国产乱码久久久久久久久 | 久久精品亚洲精品 | 一区二区三区四区免费观看 | 久久久成人一区二区免费影院 | 欧美成人久久 | 国产精品久久久久久久久久久久久久 | 日本亚洲一区二区 | 亚州午夜精品 | 久久精品视频在线播放 | 免费在线观看黄网站 | 欧美精品一区二区三区在线 | 狠狠爱网址 | 香蕉超碰 | 国产精品视频网 | 久久国产欧美一区二区三区精品 | 91久久北条麻妃一区二区三区 | 亚洲免费成人 | 欧美高清视频一区 | 久久久xxx| 99热欧美 | 成年网站在线观看 | 暴草美女| 日韩一级免费观看 | 不卡的av在线 | 亚洲国产成人精品女人久久久 | 日韩视频在线免费观看 | 精品videossex高潮汇编 | 国产一区二区三区四区五区3d | 亚洲一区二区免费 | 人人干人人干人人 | 久久久久国产一区二区三区四区 | 99福利视频导航 | 99精品国产一区二区三区 | 久久成人国产精品 | 精品日韩欧美一区二区 | 伊人久久大香线 | 亚洲三区视频 |