Introduction to MVC(Model View Controler)
Struts : Struts is an open source framework from Jakartha Project designed for developing the web applications with Java SERVLET API and Java Server Pages Technologies.Struts conforms the Model View Controller design pattern. Struts package provides unified reusable components (such as action servlet) to build the user interface that can be applied to any web connection. It encourages software development following the MVC design pattern.
Overview of MVC Architecture
The MVC design pattern divides applications into three components:
* The Model maintains the state and data that the application represents . * The View allows the display of information about the model to the user.
* The Controller allows the user to manipulate the application .
In Struts, the view is handled by JSPs and presentation components, the model is represented by Java Beans and the controller uses Servlets to perform its action.
By developing a familiar Web-based shopping cart, you'll learn how to utilize the Model-View-Controller (MVC) design pattern and truly separate presentation from content when using Java Server Pages.
Applying MVC in Servlets and JSP
Many web applications are JSP-only or Servlets-only. With JSP, Java code is embedded in the HTML code; with Servlets the Java code calls println methods to generate the HTML code. Both approaches have their advantages and drawbacks; Struts gathers their strengths to get the best of their association.
View on JSP The early JSP specification follows two approaches for building applications using JSP technology. These two approaches are called as JSP Model 1 and JSP Model 2 architectures.
JSP Model 1 Architecture In Model 1 architecture the JSP page is alone responsible for processing the incoming request and replying back to the client. There is still separation of presentation from content, because all data access is performed using beans. Although the JSP Model 1 Architecture is more suitable for simple applications, it may not be desirable for complex implementations.
JSP Model 2 Architecture - MVC
The Model 2 Architecture is an approach for serving dynamic content, since it combines the use of both Servlets and JSP. It takes advantages of the predominant strengths of both technologies, using JSP to generate the presentation layer and Servlets to perform process-intensive tasks. Here servlet acts as controller and is in charge of request processing and the creation of any beans or objects used by the JSP as well as deciding depending on the user’s actions, which JSP page to forward the request to. Note that there is no processing logic within the JSP page itself; it is simply responsible for retrieving any objects or beans that may have been previously created by the servlet, and extracting the dynamic content from that servlet for insertion within static templates. Limitation in traditional MVC approach The main limitation in the traditional MVC approach is, in that there is no separation of business logic (validation/ conditions/ anything related to business rules) from controller (is responsible for controlling of the application flow by using static/dynamic request dispatcher. MVC Model 2 Architecture is Model View Controller
1.Client submits login request to servlet application 2.Servlet application acts as controller it first decides to request validator another servlet program which is responsible for not null checking (business rule) 3.control comes to controller back and based on the validation response, if the response is positive, servlet controller sends the request to model 4.Model requests DB to verify whether the database is having the same user name and password, If found login operation is successful 5.Beans are used to store if any data retrieved from the database and kept into HTTPSession 6.Controller then gives response back to response JSP (view) which uses the bean objects stored in HTTPSession object 7.and prepares presentation response on to the browser
|
| Author: Deepu 19 Mar 2008 | Member Level: Gold Points : 2 |
But i want to know that how can we implement that MVA architecture in our project.i.i Documentation part of the project. -Deepu
|
| Author: Aparanjitha 19 Mar 2008 | Member Level: Gold Points : 2 |
Draw mvc architecture in your project documentation that is pictorial representation of heirarchy of directories in your project then it will give mvc architecture
|
| Author: Deepu 19 Mar 2008 | Member Level: Gold Points : 2 |
Thank you,for your explanation.Its quite helpful for me in my project.Should we need to write the directories of the source code.Please give me reply. -Deepu
|
| Author: Aparanjitha 19 Mar 2008 | Member Level: Gold Points : 1 |
ya u can do it
|