Monday, April 6, 2009

Life Cycle of Struts Request

The three categories of processing (simple/complex validation, business logic, and flow control) come into play when an incoming HTTP request is generated by a user submitting form data.

With servlet technology all such processing is done by servlets, Servlets are just Java objects, usually your subclasses of HttpServlet.
Even JSP pages are converted at runtime into servlet classes—actual .java source files. These autogenerated Java source files are later compiled.
Since Struts is built on servlet technology, it is no exception to this rule.

All submissions of form data to a Struts application are intercepted by a single “master” servlet, an instance of ActionServlet, which is a part of Struts.

This master servlet is responsible for delegating the actual work of your application to your subclasses of ActionForm and Action.

ActionServlet and its helper classed are responsible for many other behind- the-scenes things like pooling Action subclasses for efficiency, reading configuration data, or initializing Struts extensions called plug-ins. These activities are invisible to Struts developers, and are one good reason why Struts is so easy to use. You don’t have to know how the clock works to tell the time!


The incoming form data is processed in stages:
  • Data transfer: Form data is transferred to your ActionForm subclass.
  • Simple validation: The form data in this subclass is passed through simple validation. If simple validation fails, then the user is automatically presented with the form with the error messages detailing the errors. This is a typical scenario, but the details would depend on how you configured Struts.
  • Further processing: Form data is next sent to your Action subclass for complex vali- dation and the processing of business logic.
  • Your Action subclass also specifies the “next” page to be displayed, and this ends the processing of a single request.

No comments:

Post a Comment

Followers