In web applications developed with Struts frameworks, it is generally used to build an actionform for each action in the database, and each table member is actions. For example, in a simple application of a user registration, there may be some operations: new registration an account, modify an existing account, and delete an account. (Three basic operations corresponding to the database table).
The easiest way is to write three Actions, respectively, each Action corresponds to an ActionForm. This is relatively simple, but will result in a large number of classes, and the ActionForm corresponding to a table is generally the same (maybe some fields are not). So I use a registrationform.java in the struts-example in Struts I have a good action. In addition, in order to reduce the number of JSPs, it uses the
But even if this, the operation of each table still corresponds to several Actions. So Struts provides Dispatchction
[org.apache.struts.Actions.dispatchaction] To reduce the number of Actions of these related business logic to facilitate the development and maintenance of the system. Its method is:
1. Write an action inheritance Dispatchation. If it is a tool such as JBuilder, remember to remove the exact () method, because Struts will call this method first, if not, it will only look for an action mapping
The Parameter property is called according to this attribute to call the corresponding method. If you don't find the method specified by parameter, it will be wrong. JBuilder generates an exception-throwing Execute method, and we can develop this method originally, so habits a NULL, and then we implemented the method specified by parameter, and the results have been unable to pass.
2. Action mapping is added to the action mapping in the struts-config.xml file to use different methods to indicate different parameters, habits to take Parameter to Method, and the value of the facts can be made. If there is a request parameter in the actionform, it will cause errors. Action [/ newaccountaction] Does not contact method name is the error when I add a name for the text input box in the request (I entered when I entered).
In addition, many business logic associated with updating databases will need to verify, and only verify data in ActionForm before or before org.apache.struts.valiDator. If the client also needs to be verified, the JSP programmer must write JavaScript code yourself. This can be a very headache, because the general Java IDE does not debug the function of JavaScript, sometimes I have found that Document.FormName is wrong. . After introducing Validator Plugin, everything becomes simple, to make some basic verification (type, email, etc.) simply in validation.xml, or write an actionform's validate () method.
How to use: 1. Write a class inherited validatorform [org.apache.struts.validator.validatorForm], if you want to use dynamic FORMBEAN, modify the Struts-Config.xml FORM element.
2. Add