Form verification and business logic verification in Struts is a very troublesome thing, reading, online understanding of the basic knowledge of ActionMessage and ActionerRors, can be tested on or online routines to try. Wrong, wrong, wrong, still wrong, I said yes, my program results have errors, rather than really showing verification error messages.
What's going on? After a day of continuous testing, success ...
Experience is:
Using ActionerRors in ActionFrom
Error message Add add ("Error_Key", New Actionerror ("Error.input.name"))
JSP use
Display error.
Using ActionMessages in ACTOIN
Error Message Add ADD ("Error_Key", New ActioInMessage ("ERRORS.LOGINERROR"))
JSP use
To display an error. Don't worry about the ID and Name, as long as both, you will show all of the actionMessages out.
Here is my code
Login.jsp:
html: Messages>
Username:
Userpwd:
Year:
html: select>
html: form>
LoginAction
Loginform loginform = (loginform) Actionform; actionerrors errors = new actionerror (); if (loginform.getusername (). Tostring (). Equals ("admin") && loginform.getuserPwd (). Tostring (). Equals ("111") ) {} else {errors.add ("Loginerror", new actionMessage ("ERRORS.ISEMPTY ()) {SaveErRors (httpservletRequest, Errors); Return (ActionMapping.Findforward" "));} Return (ActionMapping.FindForward (" seccess "); loginform
ActionerRORS ERRORS = new actionerrors (); if (username == null || username.length () <1) {ErrorS.Add ("name", new actionerror ("test.name"));} if (userpwd == NULL || Userpwd.length () <1) {Errors.Add ("PWD", New ActionError ("Test.PWD"));}
Return Errors;