The struts framework allows only one Actionservlet class to exist in the application, but there can be multiple, customized requestprocessor classes, each of which can have a separate requestprocessor class.
Actionservlet is primarily responsible for initializing, and introducing requests and finding the right requestrrocessor, after which the real work is requestproecssor and action.
The last time we talked about Actionservlet's process method would eventually call the Requestprocessor class's process method. This method is described below.
I. Requestprocessor's process approach Code public void process (httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { // wrap multipart requests with a special wrapper request = processmultipart (request); // identify the path component we will use to select a mapping string path = processpath (Request, response);      &NBsp; if (path == null) { return; } if (log.isdebugenabled ()) { log.debug ("processing a '" + request.getmethod () + "' for path '" + path + ""); } // select a locale for the current user if requested processlocale (request, reSponse); // Set the content type and no-caching headers if requested processcontent (Request, response); processnocache (Request, response); // general purpose preprocessing hook if (Request,!processpreprocess response)) { Return } this.processcachedmessages (Request, response); // identify the mapping for This request actionmapping mapping = processmapping (Request, response, path); if (mapping == null) { return; } // check for any role required to perform this action if (!processroles (Request, response, mapping)) { Return } // process any actionform bean related&Nbsp;to this request actionform form = processactionform (request, response, mapping); processpopulate (Request, response, form, mapping); // validate any fields of the actionform bean, if applicable try { if (!processvalidate (request, response, form, mapping)) { return; } } catch (invalidcancelexception e) { actionforward forward = processexception (Request, response, e, form, mapping); processforwardconfig ( Request, response, forward); return; } catch (ioexception e) { throw e; } catch (servletexception e) { throw e; }      &Nbsp; // Process a forward or include specified by this mapping if (!processforward (request, response, mapping) ) { return; } if (!processinclude (request, response, mapping)) { return; } // Create or acquire the Action instance to process This request action action = processactioncreate (request, response, mapping); if (action == null) { return; } // call the action instance itself actionforward forward = processactionperform (Request, response, action, form, mapping); &nbsP; // process the returned actionforward instance processforwardconfig (request, response, Forward); }
1) calling the Processmultipart () method
If the HTTP request is post and contenttype is "Multipart/form-data", the standard HttpServletRequest object will be repackaged to facilitate processing of the "multipart" The HTTP request for the type. If the request is a get, or the positive Congtenttype property is not "Mulitipart", the original HttpServletRequest object is returned directly.
2) calling the Processpath () method
Gets the path to the requested URI, which can be used to select the appropriate struts action component.
3) Calling the Processlocale method
When the Locale property of the Controllerconfig object is true, the locale information contained in the user request is read, and the locale instance is saved in the session scope.
4) Call Processcontendtype (ContentType) method
Reads the Conttenttype property of the Controllerconfig object, and then calls the Response.setcontenttype (ContentType) method to set the document type and character encoding of the response result.
The ProcessContent () method is as follows
Code protected void ProcessContent (HttpServletRequest request, HttpServletResponse Respo NSE) {String contentType = Moduleconfig.getcontrollerconfig (). getContentType (); if (ContentType!= null) {Response.setcontenttype (contentType); } }
5) calling the Processnocache () method
Reads the NoCache property of the Controllerconfig object and, if the NoCache property is true, adds a specific header parameter to the response result: Pragma,cache-control and expires,
Prevents the page from being stored in the client's browser's cache, the code for the Processnocache method is as follows:
Code Protected void processnocache (httpservletrequest request, httpservletresponse response) { if ( Moduleconfig.getcontrollerconfig (). Getnocache ()) { response.setheader ("Pragma", "No-cache"); response.setheader (" Cache-control ", " no-cache,no-store,max-age=0 "); response.setdateheader (" Expires ", 1); } }
6) calling the Processpreprocess () method
The method does nothing. Returns true directly. Subclasses can override this method.
Performs a customized preprocessing request operation.
7) calling the Processmapping () method
Find the actionmapping that matches the URI of the user request, and if no such actionmapping exists, return the appropriate error message to the user.
8) calling the Processroles () method
Determine whether the security role is configured for the action, and if the security role is configured, call the IsUserInRole () method to determine whether the current user has the required role and, if not, end the request processing process. Returns the appropriate error message to the user.
9) calling the Processactionform () method
First of all to determine whether the actionmapping configured Actionform, if configured Actionform, first from the existing scope of Actionform (request or session) to find the Actionform instance, if not, Create an instance, then save it in the appropriate range, and save with the property key that is the actionmapping name attribute.
10) calling the Processpopulate () method
If Actionform is configured for actionmapping, the Reset () method of the Actionform is invoked first, and the form data in the request is assembled into the actionform.
11) calling the Processvalidate () method
If Actionform is configured for actionmapping, and Actionmapping's Validate property is true, the Actionform () method is invoked. If the Actionerrors object returned by the Validate method contains a Actionmessage object, the form validation fails. Place the Actionerrors object in the request range and forward the request to the Web component specified in the Actionmapping input property. If the Actionform Validate method performs form validation successfully, proceed to the following processing process.
12) calling the Processforward () method
Determines whether the forward attribute is configured in actionmapping. If this property is configured, the RequestDispatcher forward method is invoked and the request processing process ends. Otherwise proceed to the next step.
13) calling the Processinclude () method
Determines whether the include attribute is configured in actionmapping. If this property is configured, the RequestDispatcher include method is invoked and the request processing process ends. Otherwise proceed to the next step.
14) calling the Processactioncreate () method
Decide whether to have this action instance in the action cache, and if not, create a new action instance and put it in the action cache. You can see that the action also has only one instance running.
15) Call Processactionperform
The method calls the Execute method of the action instance, which is in Try/catch and catches the exception. The Processactionperform () side puts the code as follows.
Code Protected actionforward processactionperform ( Httpservletrequest request, Httpservletresponse response, Action action, actionform form , actionmapping mapping)   &NBSp; throws ioexception, servletexception { try { return (Action.execute (mapping, form, request, response)); } catch (exception e) { return (ProcessException (request, Response, e, form, mapping)); }
16) Calling the Processactionforward method
The Actionfoward object returned by the Excute method of your action is passed to it as a parameter, and the request forwarding information of the object package is processactionforward to perform request forwarding or redirection.
In the process method of the Requestprocessor class, the properties of the Controllerconfig, Actionmappig, and actionforward strengths are accessed. The Controllerconfig class corresponds to the <controlle>r element of the struts configuration file, actionmapping classes and <action> elements correspond, Actionforward and < Forward> elements, the process method obtains related configuration information by accessing the properties of these three class instances.
With all this writing, Requestprocessor has done more than enough.
two. Extended Requestprocessor Class
If you want to modify some of the default features of Requestprocessor, changing overrides the related methods in the Requestprocessor base class.
Code public class customrequestprocessor extends requestprocessor{ protected void processPreprocess (Httpservletrequest request, HttpServletResponse Response) { .... ... }
in the Struts configuration file,< in the "...", "..." The Processorclass property of the controller> element is used to configure your own Requestprocessor class code </controller contenttype= "text /html:charset= "GB2312" locale= "true" nocache= "true" processorcalss= " Com.test.CustomRequestProcessor "/>&NBSP;&NBSP;&NBSP;