aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes wat is MVC architecture ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "wat is MVC architecture ?" Watch "wat is MVC architecture ?" New topic
Author

wat is MVC architecture ?

Deepika Wadhwa
Ranch Hand

Joined: Aug 05, 2000
Posts: 57
hi all,
can anybody plz give me brief idea of MVC arch.
yday while i reading diff b/w JSP and servlets , i read that 'coz of MVC arch JSP is more powerful ...
but i don't know what is MVC ?
plz help
thanx
Deepika

Avijeet Dash
Ranch Hand

Joined: Jan 21, 2001
Posts: 148
Model-View-Controller
Model -> is the Tables in Database
Controller -> is the logic which interfaces with Database and GUI
View -> is the GUI
Its basically the Observer pattern, where the (listner)observer sees for a change and notifies the interested parties. its asynchronous in nature.
For Example JList and JListmodel.
//create Jlist
JList list = new JList()
//get Model
LisModel model = list.getModel()

//add data listner to model
addListDataListener(ListDataListener l)
Add a listener to the list that's notified each time a change to the data model occurs.

and whenever data changes the view gets changed and vice versa.
hope its clear.
regards
Deepika Wadhwa
Ranch Hand

Joined: Aug 05, 2000
Posts: 57
in that manner it should be same for both JSP and servlets , both throws html data to browser.both supports database connectivity ...
then where does MVC come into pic ?

John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1441
Here is a writeup describing MVC. There are lots more on the web or you can do a search here in the Saloon and see what other people have posted about MVC.
John


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Avijeet Dash
Ranch Hand

Joined: Jan 21, 2001
Posts: 148
Servlets don't separate view and controller. u write the html and business logic in servlet. in JSP only the dynamic view comes and business logic is in beans or other java classes.

Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
This is my first posting in the forum, so let me say "Hi!" to everybody first.
Now on the question asked: MVC stands for Model-View-Controller. It was first developed in the Smalltalk community. If you want to see a discussion on MVC and how it is used in the Swing tooklit a good reference is "Graphic Java vol.2" by David Geary. The idea behind MVC is that you separate the look & feel (i.e. the GUI) of your application from the actual data of the application which in MVC lingo is "the model". Now wrt the look & feel, the look is "the view" and the feel is "the contoller".
To wrap up:

  • Model is the data you have (e.g. a table)
  • View is how you show them to the user
  • Controller is how you react to user events (synonyms for controller could be "listener" or "business logic"

  • Swing, by separating V&C from M (V&C is referred to as look & feel in Swing talk), enables the so-called "pluggable" look & feel whereby you can present your data (and react to user events) in different ways, while keeping the same underlying data model.
    Hope this helps,
    Panagiotis.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Avijeet Dash:
Servlets don't separate view and controller. u write the html and business logic in servlet. in JSP only the dynamic view comes and business logic is in beans or other java classes.

Neither servlet or JSP support MVC particularly well, IMHO. It is up to you, the developer, to make sure you actually use this architecture. In fact this often doesn't happen and many of the JSPs I see in practice are riddled with Java code.
If you want to implement your web application using MVC, you would typically use JSPs, servlets, and beans. JSPs are presentation-centric, they are presentation with embedded code. Servlets are code-centric. Your choice between them depends on what you want to do.
The Model typically consists of JavaBeans, Enterprise JavaBeans, or Java classes. It certainly should not be a JSP or servlet as it does not handle requests or generate responses.
The View, then, would be a JSP because the presentation is so central to it. Beans and tag libraries can help you squeeze the last bits of Java code out of it.
The Controller is best driven from a servlet, as it is only logic (code) without any presentation element. In my experience the Command pattern works particularly well here, the task of the controller servlet is then to invoke the right command(s) in response to an incoming request.
- Peter

[This message has been edited by Peter den Haan (edited January 30, 2001).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I used MVC for my application.
I implemented using 3 JSPs to outlines
presentation of business related graphics.
and business logic.
I can say that
create xxx_page.jsp
{ include xxx_code.jsp
include xxx_pres.jsp.
}
in this way seperate your pres - presentation
and code - code which interfaces with EJB and etc.
I think this will help.
Regards
jaisinh
Deepika Wadhwa
Ranch Hand

Joined: Aug 05, 2000
Posts: 57

So reading so many responses i should conclude that if we are using JSP only for View (presentation logic eg HTML code) and for controller thing either we are using Java beans /EJB etc, those are talking to model (tables/database ), then only we are implementing MVC architecture.
and if we are doing processing too in JSP file then it won't.
as generally we use jsp to seperate the business logic from presentation logic , so v can say it supports MVC whereas Servlets contains both presentation logic as well as Business logic ...so it doesn't.

now i got a good feel of MVC.
thanx a lot to all ,

Deepika
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wat is MVC architecture ?
 
Similar Threads
Re : Which is better way
MVC Architecture for Web
Online Database
Pagination logic in jsp
problem in connecting struts to ejb