1.

What is a Request Processor and a Request Dispatcher in context with Java?

Answer»

Request Processor: Request processor is a class given by the struts framework that is responsible for handling requests and responses. If we want to change our controller, we can do so in this class. Since version 7.16, the Request processor has been able to perform asynchronous requests in a dedicated thread pool. The majority of RequestProcessor use cases begin with building your own RequestProcessor instance (which by itself is quite LIGHTWEIGHT).

Request DISPATCHER: Request Dispatcher is an interface that allows requests to be dispatched from one page to another within an application (page may be a servlet file, JSP, etc.). The RequestDispatcher interface  offers the following two approaches:

  • PUBLIC void forward(ServletRequest request, ServletResponse response) THROWS ServletException, java.io.IOException: The forward() method is used to redirect a client's request to a different RESOURCE (HTML file, servlet, jsp etc). The control is passed to the next resource called when this method is invoked. The include() method, on the other hand, inserts the content of the calling file into the called file. The control remains with the calling resource after calling this method, but the processed output is included in the called resource. The process is depicted in the diagram below: 
  • public void include(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException: The include() method is used to pass the contents of the caller resource to the called resource. Control remains with the caller resource when this method is called. It merely incorporates the calling resource's processed output into the called one. The diagram below depicts how it works: 


Discussion

No Comment Found