The Model View Controller (MVC) paradigm (also known as Model 2) applied to web applications lets developer separate display code (JSP, tag libs) from flow control logic (action classes). Typically MVC design pattern combines the use of both servlets (controller) and JSP pages (view). It takes advantage of the strengths of both technologies, using JSP to generate the presentation layer and servlets to perform process-intensive tasks. Davisor Chart has been designed so that it can be easily integrated to MVC application.

The Controller portion of the application is focused on receiving requests from the client, deciding what business logic function is to be performed, and then delegating responsibility for producing the next phase of the user interface to an appropriate View component.
The Model portion of an MVC-based system typically comprises JavaBean classes that define the internal state of the system and the actions that can be taken to change that state.
The View portion of the application is used to create the user interface based on the data read from the model.
Following example includes two Java files (one servlet and one Java bean) and one JSP file.
Controller Java code
Model Bean Java code
Inside the controller code a Chart object is created and set to a servlet request object. A <chart:out> tag that sits in the "view.jsp" page reads the Chart object from the request object using id that is given with a "def" attribute.
Please note: because the Chart object represents a ready chart, only out tag's "markupType" attribute has any effect on the final result. Out tag's attributes width, height, chartType, contentType, resolution and attributes are ignored completely.
When clicking "Call" button user should see following chart image. The view display is generated by "view.jsp" (located in this directory).
|
| A chart result from servlet and JSP co-operation. |
Apache Struts is a popular implementation of MVC paradigm. The Struts framework provides several components that make up the Control layer of a MVC-style application. These include a controller servlet, developer-defined request handlers, and several supporting objects. The Struts controller servlet typically routes HTTP requests to request handlers that are called Actions. Actions often forwards the request to a JSP page. The previous MVC example code can be reused at a user defined Action class, enabling charting for a Struts application.