ActionMApping class
The relevant information mapped to a specific Action is stored in an actionMApping. ActionServelt transmits actionMApping to an Execute () method of the ActionMApping, Action will use an actionMApping's FindForward () method, this method returns an actionforward that specifies the name, so that action Completed local forwarding. If you do not find a specific ACTIONFORWARD, you will return a NULL.
ActionMApping method:
Public ExceptionConfig FindException (Class Type) Find an exception object
Public ActionForward FindForward (String Name) can dynamically add ActionForward in the mapping:
Public String [] Findforwards () Find a list of ActionForwards that can be used by action
Public ActionForward GetInputForward () Gets the input ActionFORARD for this action.
Actionmapping inherits in org.apache.struts.config.ActionConfig
The Action class Action class really implements the transaction logic of the application, which is responsible for processing the request. After receiving the request, the ActionServlet will: 1. Select the appropriate action2 for this request. If you need, create an instance of an action 3. Call an Execute () method If the ActionServlet does not find a valid map, it will call the default action Class (defined in the configuration file). If you find the ActionServlet forward to the appropriate actionMApping class, this action uses actionMapping to find local forwarding, then get an actionMApping property. The ActionServlet also transmits the servletRequest object or HttpServletRequest object according to the signature of the servlet and the overcute () method. All Action classes expand the org.apache.struts.Action.Action class and override a certain execute () method defined in the class.
There are two execute () method: non-treated HTTP (general) request: public ActionForward execute (ActionMapping action, Acionform form, ServletRequest request, ServletResponse response) throws java.lang.Exception HTTP requests: public ActionForward execute (ActionMapping action, ACIONFORM FORM, HTTPSERVLETREQUEST REQUEST, HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESERESE RESPONSE) The "Throws Java.lang.ExcectionAction class must be programmed in a" thread security "mode, because the controller will share multiple simultaneous requests to share with one instance, corresponding, in design Action class I need to pay attention to the following: I can't use the status information of the specific request. They share the global resource across the request in the same operation. If you want to access, if you want to access, if you want to access, when you want to access, It is necessary to protect, then access to the method of synchronization Action class In addition to the execute () method, there is also the following methods: You can get or set the area associated with the request: public local getRequest Request Public void setLocale (httpservletRequest request) , locale locale) to obtain an application message resources: whether protected MessageResources getResources (HttpServletRequest request) protected MessageResources getResources (HttpServletRequest request, String key) checks the user clicks "cancel" button on the form, and if so, returns true: public Boolean isCancelled (HttpservletRequest request) When an application has an error, the Action class can store an error message using the following method: Public Void SaveErrorS (httpservletRequest Request, Actionerror SERRORS) Public Void Savement, ActionMessages Messages ActionError instance is used to store an error message, and this method stores an ActionError object in a request attribute list under false key. The JSP page can display these error messages by using a custom tag defined in the Struts tag library. ActionMessages are used to store some prompt information, not errors, and can use tagged reality in the JSP page. Request valid processing, prevent repetition submission can be effectively used using tokens.
protected String generateToken (HttpServletRequest request) to create a token .protected boolean whether isTokenValid (HttpServletRequest request) to check the token is valid protected boolean isTokenValid (HttpServletRequest request, Boolean reset) checking whether the token is valid, and resets the token (if reset is true ) protected void resetToken (HttpServletRequest request) reset token protected void saveToken (HttpServletRequest request) was added token database connection protected DataSource getDataSource (HttpServletRequest request) protected DataSource getDataSource (HttpServletRequest request, String key) other ActionServlet getServlet () can be obtained This Action configuration information.dispatchaction class Dispatchaction is the subclass of the Action, the main function can be realized, dynamic method calls. For example, there is a method Update (ActionMApping Mapping, ActionForm Form, HttpServletRequest Request, HTTPSERVLETREST Request, HttpservletResponse Response), can call the UPDATE method via SaveSubscription.do?method=UPDate. This class does not require us to implement other methods, we only need to implement XXX (ActionMApping Mapping, ActionForm Form, HttpservletRequest Request, HttpservletResponse Response). At http://www.chinajavaworld.net/forum/topic.cgi?forum=48&topic=116666ow=150 and http://www.chinajavaworld.net/forum/topic.cgi?forum=48&topic=1129 is pair dispatchaction and Detailed introduction to lookupdispatchaction
SwitchAction class Switch is a subclass of Action, the main function is to forward requests between different modules. It is useful for large projects. Specifically see http://www.chinajavaworld.net/forum/topic.cgi?forum=48&topic=1029&show=0
Actionform Category Self User creates an actionform bean for each form in the application, for each bean defined in the struts-config.xml file, the framework will do the following before calling the action class's execute () method: Under the associated keyword, it checks the user session (or request) for the appropriate class instance, if there is no Bean available in the session (or request), it will automatically create a new bean and add it to The user's session (or request). As for the session or request depends on the scope attribute of the action in struts-config.xml. When creating an actionform, the value in the request will be initialized after the value of the request is performed. For each parameter corresponding to the bean property name, the Action calls the corresponding setting method. When Action Execute () is called, the latest ActionForm bean is delivered to it, and the parameter value can be used immediately. ActionForm class extension org.apache.struts.Action.Actionform class, the BEAN created by program developers can include additional properties, and ActionServlet may use reflection (allowing recycling information from loaded objects) to access it. Actionform class provides another means of handling errors, provides two methods: Public ActionErrors validate (ActionMappin mapping, ServletRequest request) Public ActionErrors validate (ActionMappin mapping, HttpServletRequest request) you should cover validate in their own bean in () method, And set the validate of the
Actionform Property Allowed Type Boolean, Byte, Short, CHAR, INT, Long, Float, Double, Boolean, Btye, Short, Character, Integer, Long, Float, Double, String, Date, Time, Timestamp, Object, and above Array of types. If the attribute of the ActionForm bean is an array, the appropriate settings and reading methods are partially modified. For array setxxx (...), and getxxx () is not significant in the JSP page. SetXXX (INDEX, ...) methods and getxxx (int index) methods should be added. These two methods are more meaningful for JSP pages. The Property in JSP should be XXX [0]. If the attribute of the ActionForm bean is a map, method Setxxx (String Key, ...) and getXXXX (String Key) allow the JSP page to access the MAP property. The Properry in JSP should be XXX (Keyname). The HTML input box can be easily achieved by getxxx (int index), setxxxx (int index, ...), getXXX (String Key), SetXXX (String Key, ...). For example: public class Fooform extends Actionform {private String yourName; public String getYourName () {return yourName;} public void setYourName (String yourName) {this.yourName = yourName;} private final Map values = new HashMap (); public void setvalue (String Key, Object value) {VALUES.PUT (Key, Value);} public object getValue (String Key) {if (Values.Containskey (Key)) {returnis.get (key);} else {return " ;}} ...}
ValidatorForm class org.apache.struts.validator.validatorform class inherits the Actionform class. Use this category that you can easily implement the verification of the form parameter. At the time of the check, use the Name property in the action element in Struts-Config.xml, determine the basis for obtaining the verification rule in Validation.xml. Using this class can easily solve the problem of using different verification rules in different Actions. I no longer need us to write the Validate method in the class that inherits the ValidatorForm. Instead, the validate method in the ValidatorForm is performed by reading the description information in Validation.xml. You can easily implement the verification of the script using the ValidatorForm can also be implemented. Newly added ways in ValidatorForm: int getPage () java.util.map getResultValueMap () ValidatorResults getValidatorResults () void setpage (int page) Void SetValidatorResults () Use this class to greatly improve our programming efficiency. ValidatorActionform class org.apache.struts.validator.validatorActionform class inherits the ValidatorForm class. Use this category that you can easily implement the verification of the form parameter. At the time of the check, use the Path property in the action element in struts-config.xml, determine the basis for obtaining the verification rules in Validation.xml. The DynaActionform class org.apache.struts.Action.DynaActionform class inherits the Actionform class. Use this category that you can easily implement dynamic forms. Create an uncertain form, if the JSP changes only if you need to modify the JSP page and the form-bean element in the Struts-Config.xml file. There is a class of Actionform in our program. Method in DynaActionform: Boolean Contains (String Name, String Key) Detects Name (Key) whether there is existence in ActionForm. Object Get (String Name) A value of Name from the ActionForm. Object Get (String Name, int index) acquirs the index value of the Name object from the ActionForm. Object Get (String Name, String Key) A value corresponding to the key of the Name object is obtained from the ActionForm. Map getMap () Returns the list of object attribute names contained in the object. Void Remove (String Name, String Key) Deletes an element. Void Set (String Name, INDEX, OBJECT VALUE) assigns the properties in the ActionForm. Void Set (String Name, Object Value) Void Set (String Name, Strign Key, Object Value)
DynavalidatorForm class org.apache.struts.validator.dyNavalidatorForm class inherits the DynaActionform class. Use this category that you can easily implement the verification of the form parameter. At the time of the check, use the Name property in the action element in Struts-Config.xml, determine the basis for obtaining the verification rule in Validation.xml. As for the verification, with ValidatorForm. The DynaValidatorform newly added method: int getPage () java.util.Map getResultvalueMap () ValidatorResults getValidatorResults () void setPage (int page) void setValidatorResults () DynaValidatorActionform class org.apache.struts.validator.DynaValidatorActionform class inherits DynaValidatorform class . Use this category that you can easily implement the verification of the form parameter. At the time of the check, use the Path property in the action element in struts-config.xml, determine the basis for obtaining the verification rules in Validation.xml. As for the verification, with ValidatorForm.
The ActionForward class ActionForward class inherits org.Apache.struts.config.ForwardConfig. ForwardConfig method: String getName () virtual name string getPath () actual path Boolean getRedirect () Whether to redirect void setName (String name) Void setPath (String Path) Void Setredirect (Boolean Redirect)
The ActionForWard is the purpose of which is forwarded to the processing result of the Action class to the destination. The Action class obtains the handle of the ActionForward instance, and then you can use two methods to return to the ActionServlet. The ActionMApping instance is transmitted to the execute () method, using an actionMApping's FindForward (String Name) to get a global forwarding or local forwarding according to the name. Another is to call one of the following constructor to create their own one example: public ActionForward () public ActionForward (String path) public ActionForward (String path, Boolean redirect) public ActionForward (String name, String path, Boolean redirect) public ActionForward (String name, String path, Boolean redirect, boolean contextRelative) method, or the following construction (ActionForward following is a subclass of) ForwardingActionForward () ForwardingActionForward (String path) RedirectingActionForward () RedirectingActionForward (String path)