• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wat is MVC architecture ?

 
Deepika Wadhwa
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Avijeet Dash
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic