What is RequestProcessor, how to extend it?

RequestProcessor is a class which is used by ActionServlet to maintain the state and process the activities in different level of request lifecycle.

RequestProcessor have following method into it:
1.) processPreprocess – Used to execute line of code before the action servlet start working on any request.
2.) processPostprocess – Used to run snippet after the process method finish its work.

Below is the flow of work for struts with requestprocessor:

Can we create our own RequestProcessor?
Yes, We can create your own RequestProcessor class and can override any of above methods to fulfill the Business requirement.

Add below snippet into Struts-Config.xml

<controller
contentType=”text/html;charset=UTF-8″
debug=”0″
nocache=”true”
processorClass=”com.testComp.MyOwnRequestProcess”/>

Create a class with below declaration:

public class MyOwnRequestProcess extends RequestProcessor {

Override your method with given below code:

protected boolean processPreprocess (HttpServletRequest req,HttpServletResponse res){
Add Code here, which will process before process method execute.

You can also override its other method too.