¿ìËÙÒµÎñͨµÀ

Struts´ÓÁ㿪ʼÎå¡¢StrutsÖÐÑéÖ¤Êý¾ÝʵÀý - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-15
ÊÇÏÔʾ´íÎóÐÅÏ¢£¬¾ßÌå´úÂëƬ¶ÎÈçÏ£º

£ºÓÃÓÚÊä³öÏûÏ¢¡£ÊôÐÔ½éÉÜÈçÏ£º

n name£ºÖ¸¶¨ActionMessages¶ÔÏó´æ·ÅÔÚrequest»òsession·¶Î§ÄÚµÄÊôÐÔkey¡£±êÇ©´¦ÀíÀཫ¸ù¾ÝÕâÒ»ÊôÐÔkeyÀ´¼ìË÷request»òsession·¶Î§µÄActionMessages¶ÔÏó¡£

n messageÊôÐÔ£ºÖ¸¶¨ÏûÏ¢µÄÀ´Ô´¡£Èç¹ûΪtrue,Ôò´Órequest»òsession·¶Î§ÄÚ¼ìË÷³öÊôÐÔkeyΪGlobals.MESSAGE_KEYµÄActionMessages¶ÔÏ󣬴ËʱnameÊôÐÔÎÞЧ£»Èç¹ûΪfalse,Ôò¸ù¾ÝnameÊôÐÔÀ´¼ìË÷ActionMessage¶ÔÏó£¬Èç¹û´ËʱûÓÐÉèÖÃnameÊôÐÔ£¬½«²ÉȡĬÈÏÖµGlobals.ERROR_KEY.messageÊôÐÔµÄĬÈÏֵΪfalse¡£

n idÊôÐÔ£ºÓÃÀ´ÃüÃû´ÓÏûÏ¢ÖмìË÷³öÀ´µÄÿ¸öActionMessage¶ÔÏó£¬ËüºÍ±êÇ©µÄnameÊôÐÔÆ¥Åä¡£

£º±íʾÏÔʾjavaBean»òÆäÊôÐÔµÄÄÚÈÝ¡£

5¡¢ÔËÐÐ

´ò¿ªIE,¼üÈëÈçϵØÖ·£ºhttp://localhost:8080/Struts1_Login/login.jsp

²»ÊäÈëÈκζ«Î÷£¬ÎÒÃÇÖ±½Óµã¼¸»÷“È·¶¨”£¬ÈçÏ£º

Struts´ÓÁ㿪ʼÎå¡¢StrutsÖÐÑéÖ¤Êý¾ÝʵÀý - ±à³ÌÈëÃÅÍø

Struts´ÓÁ㿪ʼÎå¡¢StrutsÖÐÑéÖ¤Êý¾ÝʵÀý(3)

ʱ¼ä:2011-08-05

¶þ¡¢StrutsµÄValidatorÑéÖ¤¿ò¼Ü

Validator Ä¿Ç°ÊÇJakarta Commons ÏîÄ¿µÄÒ»²¿·Ö£¬ËüÒ²±»°üº¬ÔÚStrutsÖ÷·Ö·¢ÀïÃ棬¿ÉÒÔÖ±½ÓʹÓÃStruts ÖÐ×Ô´øµÄValidator ¿â£¬Ò²¿ÉÒÔÈ¥ÍøÕ¾ÉÏÏÂÔØhttp://jakarta.apache.org/commons/¡£

Struts¿ò¼ÜÄܹ»Í¨¹ýActionForm BeanµÄvalidate()·½·¨¶ÔÓû§ÊäÈëµÄ±íµ¥Êý¾Ý½øÐÐÑéÖ¤¡£µ«ÊÇÕâÖÖÑéÖ¤·½Ê½ÓÖÓÐÒ»¶¨µÄ¾ÖÏÞÐÔ¡£±ØÐëÓɾßÌåµÄ´úÂëÀ´ÊµÏÖÑéÖ¤Âß¼­£¬Èç¹ûÑéÖ¤Âß¼­·¢ÉúÁ˸ı䣬¾ÍÐèÒªÖØбàд³ÌÐò´úÂë¡£´ËÍ⣬Èç¹ûϵͳÖÐÓжà¸öActionForm Bean,²¢ÇÒËûÃÇ°üº¬Ò»Ð©ÏàͬµÄÑéÖ¤Âß¼­Ê±£¬ÄÇô¿ª·¢ÈËÔ±±ØÐë¶Ôÿ¸öActionForm Bean½øÐÐÖظ´¿ª·¢ÄØ?

Validator¿ò¼ÜÄܹ»¿Ë·þÔÚActionForm BeanÖнøÐÐÊý¾ÝÑéÖ¤µÄ¾ÖÏÞÐÔ£¬ËüÔÊÐíΪStrutsÓ¦ÓÃÁé»îµÄÅäÖÃÑéÖ¤¹æÔò£¬ÎÞÐè±à³Ì¡£

Validator¿ò¼ÜÖ÷ÒªÒÀÀµÓÚÁ½¸öJARÎļþ£º

Jakarta-oro.jar

ÌṩÁËÒ»×é´¦ÀíÎı¾µÄÀ࣬¾ßÓÐÎı¾Ìæ»»£¬¹ý¼ºÍ·Ö¸îµÈ¹¦ÄÜ¡£

commons-validator.jar

ÌṩÁËÒ»¸ö¼òµ¥¡¢¿ÉÀ©Õ¹µÄÑéÖ¤¿ò¼Ü£¬°üº¬ÁËͨÓõÄÑéÖ¤·½·¨ºÍÑéÖ¤¹æÔò¡£

Ö÷ÒªµÄStrutsÑéÖ¤×é¼þ

×é¼þ

˵Ã÷

ÑéÖ¤Æ÷

´¦ÀíÔ­ÉúºÍÆäËüͨÓÃÀàÐÍ¡£»ù±¾ÑéÖ¤Æ÷°üÀ¨required£¬mask(Æ¥ÅäÕýÔò±í´ïʽ)£¬minLength£¬maxLength£¬range£¬nativetypes£¬ date£¬email£¬ºÍcreditCard¡£Ò²¿ÉÒÔ¶¨Ò嶨** (»òÕß²å¼þ) ÑéÖ¤Æ÷¡£

×ÊÔ´Îļþ

Ìṩ(±¾µØ»¯µÄ)±ê×¢ºÍÏûÏ¢¡£Ä¬ÈÏÓëStruts ¹²ÏíÏûÏ¢×ÊÔ´¡£

XML ÅäÖÃÎļþ

¸ù¾ÝÐèÒª¶¨ÒåÕë¶Ô×Ö¶ÎµÄ±íµ¥¼¯ºÍÑéÖ¤¡£ÑéÖ¤Æ÷¿ÉÒÔÔÚÒ»¸öµ¥¶ÀµÄÎļþÖж¨Òå¡£

JSP ±êÇ©

¶Ô¸ø¶¨µÄ±íµ¥»òAction ·¾¶²úÉúJavascript ÑéÖ¤Æ÷¡£

ValidatorForm

¸ù¾ÝFormBean µÄÃû³Æ×Ô¶¯ÑéÖ¤ÊôÐÔ£¨ÔÚÔËÐÐʱͨ¹ýActionMapping ²ÎÊý´«µ½validate ·½·¨)¡£±ØÐë±»À©Õ¹²ÅÄÜÌṩ±íµ¥Ö®ÉϵÄÆÚÍûÊôÐÔµÄÑéÖ¤¡£

ValidatorActionForm

»ùÓÚaction ·¾¶×Ô¶¯ÑéÖ¤ÊôÐÔ(ÔÚÔËÐÐʱͨ¹ýActionMapping²ÎÊý´«µ½validate ·½·¨)¡£±ØÐë±»À©Õ¹²ÅÄÜÌṩ±íµ¥Ö®ÉϵÄÆÚÍûÊôÐÔµÄÑéÖ¤¡£

ÓÐЩ×ֶοÉÄܱØÐëÒªÇóÓÐÊý¾ÝÊäÈë¡£¶øÓÊÕþ±àÂë×ÜÊǾßÓÐÒÑÖªµÄ³¤¶È¡£ÆäËü¹«¹²×Ö¶ÎÀàÐÍ°üÀ¨ÊýÖµ¡¢ÈÕÆÚ¡¢******ºÅÂëµÈµÈ¡£

ÑéÖ¤Æ÷±¾Éí¾ßÓÐһЩ»ù±¾µÄÑéÖ¤Æ÷À´´¦ÀíÕâЩ¹«¹²ÐèÒª£¬µ±È»»¹ÓÐÆäËüһЩÐèÒª¡£Èç¹ûÄãµÄÑéÖ¤²»Äܱ»»ù±¾ÑéÖ¤Æ÷»òÕßÕýÔò±í´ïʽÂú×㣬Äã¿ÉÒÔ¿ª·¢Äã×Ô¼ºµÄÑéÖ¤Æ÷²¢²åÈëµ½°üÖС£»ù±¾ÑéÖ¤Æ÷Ö§³**ä×ÔÉí¸½´øµÄ»ù±¾²å¼þ¡£

Struts´ÓÁ㿪ʼÎå¡¢StrutsÖÐÑéÖ¤Êý¾ÝʵÀý(4)

ʱ¼ä:2011-08-05

°²×°ºÍÅäÖÃ

Validator¿ò¼Ü²ÉÓÃÁ½¸ö»ùÓÚXMLµÄÅäÖÃÎļþÀ´ÅäÖÃÑéÖ¤¹æÔò¡£Ò»¸öÊÇvalidator-rules.xml£¬ÁíÒ»¸öÊÇvalidation.xml£¬ÕâÁ½¸öÎļþÓ¦¸Ã²¿ÊðÔÚ¶ÔÓ¦ÓÚWEBÓ¦ÓóÌÐòµÄWEB-INFÎļþ¼ÐÏ£¬¶ÔÓ¦µÄÁ½¸öjarÎļþÒ²Ìí¼Óµ½WEB-INF/libĿ¼Ï¡£

1¡¢validation-rules.xml

ÔÚvalidation-rules.xml ÎļþÖÐÅäÖÃ

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ