The previous example has shown you to customize the controller before and after any request processed. But Struts provide a class named RequestProcessor which actually done all the processing for a particular request. In Struts 1.0 the whole things are done by the ActionServlet class. But with the next release the request processing code shifted to RequestProcessor class. RequestProcessor contains the processing logic that the ActionServlet performs as it receives each servlet request from the container. You can customize the request processing behavior by subclassing this class and overriding the method(s) whose behavior you are interested in changing. the following methods are available in the RequestProcessor Class.
- processMultipart():- Handles the multipart request containing the images etc.
- processPath():- Identify and return the path component
- processLocale():- Automatically select a Locale for the current user, if requested.
- processContent():- Set the default content type with character encodings for all responses
- processNoCache():- Set the no-cache headers for all responses, if requested.
- processPreprocess():- General-purpose preprocessing hook that can be overridden as required by subclasses.
- processMapping():- Select the mapping used to process the selection path for this request.
- processRoles():- If this action is protected by security roles, make sure that the current user possesses at least one of them.
- processActionForm():- Retrieve and return the ActionForm associated with this mapping, creating and retaining one if necessary.
- processPopulate():- Populate the properties of the specified ActionForm instance from the request parameters included with this request.
- processValidate():- If this request was not cancelled, and the request's ActionMapping has not disabled validation, call the validate method of the specified ActionForm, and forward to the input path if there were any errors.
- processForward():- Process a forward requested by this mapping (if any).
- processInclude():- Process an include requested by this mapping (if any).
- processActionCreate():- Return an Action instance that will be used to process the current request, creating a new one if necessary.
- processActionPerform():- Ask the specified Action instance to handle this request.
- processForwardConfig():- Forward or redirect to the specified destination, by the specified mechanism.
Note:- The below example will demonstrate the overriding of methods in the RequestProcessor class. The example will override processPreprocess() method of the RequestProcessor Class. >
(1)Struts-config.xml file
Note - RequestProcessor mapping is given by the <controller> tag in the struts-config.xml file.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <!-- ================================================ Form Bean Definitions --> <form-beans> <form-bean name="inputForm" type="com.visualbuilder.InputForm" />
</form-beans> <!-- ========================================= Global Exception Definitions --> <global-exceptions></global-exceptions> <!-- =========================================== Global Forward Definitions --> <global-forwards></global-forwards> <!-- =========================================== Action Mapping Definitions --> <action-mappings> <action path="/submit" type="com.visualbuilder.SubmitAction" name="inputForm" scope="request" validate="false" input="/index.jsp"/> </action-mappings>
<!-- =========================================== Controller Mapping Definition --> <controller contentType="text/html;charset=UTF-8" locale="true" debug="1" nocache="true" processorClass="com.visualbuilder.CustomRequestProcessor" /> <!-- ======================================== Message Resources Definitions --> <message-resources parameter="MessageResources" />
</struts-config>
|