Struts
Rewrite
Actionform
Medium
Validate
Method Verification Form
To verify the function, rewrite the verification function in org. Apache. Struts. Action. actionform.
There are two verification form functions: Public actionerrors validate (actionmapping mapping, javax. servlet. servletrequest request) and Public actionerrors validate (actionmapping mapping, javax. servlet. HTTP. httpservletrequest request) We need to rewrite the latter: The following public actionerrors validate (actionmapping mapping, httpservletrequest request) {actionerrors error = new actionerrors (); if (username = NULL | "". equals (username) {error. add ("nameerror ", New actionmessage ("JSP. login. name. error ");} If (Password = NULL | "". equals (password) {error. add ("passworderror", new actionmessage ("JSP. login. password. error ");} return error;} error in this method. the first parameter in add is the name of the error you want to use on a JSP page. There are multiple errors in a form. Of course, there must be multiple different names to remember. The string used by the parameter in actionmessage must be the key defined in the key-value in applicationresources. properties, and the value will display an error message on your page later. In addition, we also need to modify a struts configuration file. In the action in <action-mappings>, set the validate attribute to true. In the input field, add the page to display the error. Of course, form verification is used, of course, we need to configure <form-beans>, all of which are as follows <form-beans> <form-bean name = "loginform" type = "form. loginform "/> </form-beans> <action-mappings> <action Path ="/login "name =" loginform "type =" loginaction "Validate =" true "input = "/login. JSP "/> </Action-mappings> PS: The Path in <action-mapping> is received from the page. the name of the do operation. Name is the form name used, and type is an action method used to process this transaction.