j2ee: Struts Controller Components [24/27] ![]() ![]() ![]() |
The controller portion of Struts is the meat of the framework.
The ActionServlet is the controller. This servlet is registered via the web.xml file to handle all the requests for Struts (usually via a url mapping). The controller does the following:
The mapping between the view and model is all done in a configuration file, struts-config.xml. This file drives the behavior of the controller servlet. The controller forwards the request and response to the RequestProcessor for the module involved and delegates the handling to it.
Each form submitted by the user is representad as a Struts ActionForm. This is basically a JavaBean that will be populated by the framework with the data filled in by the user. Struts takes care of some of the conversion from the strings in HTTP to Java objects. The developer writes these forms in Java, or creates a DynaActionForm via an XML configuration file.
Once a form is populated and validated, the data is submitted to an Action. The Action is responsible for interacting with the model components, and then forwarding to the correct view. This is done via the execute method. The Action is essentially the same thing as a servlet, so all threading issues still apply!