The Struts2.0 Controller: FilterDispatcher
Previous | Home | Next |
The FilterDispatcher class provide the facility in struts2 framework to controlling the over all work flow .If any user send the request on the server then FilterDispatcher class first read the configuration file then invoke the action class and action class return the string .This string in which page is display in the configuration file then give the response on web browser.
The Controller handles all requests from the user and selects the view to return. When the Controller receives a request from user, Controller forwards the request to the appropriate handler, which interprets what action to take based on that request.Struts2 provides a FilterDispatcher class which is responsible for initializing a Struts applications configuration file and receiving all incoming request and on the behalf of request FilterDispatcher populating the Form Bean with data, validating the From bean and then selecting the appropriate Action class to execute .The Action class is where the Struts2 Frameworks is ends and applications model(code) begins .After doing calculations and manipulations Action class returns a key on the behalf of this key FilterDispatcher class will decides the next view.The FilterDispatcher Class is controller class that receives all incoming requests for the application. FilterDispatcher is responsible for initializing the Struts2 framework for your application. Like other servlet FilterDispatcher must be configured in web.xml (in Web application deployment descriptor).Method Descriptions:-There are two ways that FilterDispatcher can be configured to receive requests in web.xml.
- First, FilterDispatcher can be configured using path mapping, as shown here: Path mapping routes to FilterDispatcher all requests that match a specified path.The default path is /do/*. action org.apache.struts2.dispatcher.FilterDispatcher config /WEB-INF/web.xml action /do/* .
- The second way to map requests to FilterDispatcher is to use extension mapping. Extension mapping maps to FilterDispatcher all requests with the specified extension. The default extension to use is *.do action org.apache.struts2.dispatcher.FilterDispatcher config /WEB-INF/web.xml 1 action *.do
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
Previous | Home | Next |