• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC - model 2

 
Vladan Radovanovic
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
does anyone wants to explain the MVC pattern and how it is related to servlets and JSPs and Java Beans. If you can provide the simplest example I would truly appreciate it.
Thanks
Vladan
 
Mirko Froehlich
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll give it a shot. Basically, the model-view-controller pattern separates a model from its views (and, optionally, controllers to change the model). A simple example could be some kind of data (e.g. financial data), and several vies showing this data, e.g. as a chart, a graph, etc. You might also be able to modify the data in the chart, so this would also act as a controller.
In a JSP-based web application, MVC could be implemented this way: A JavaBean would contain the model, consisting of some data and business logic (e.g. a stock portfolio). One ore more JSP pages can use the JavaBean to display this model, or aspects of the model. They would also (possibly) act as controllers to modify the data in the model, e.g. by allowing the user to add a new stock to the portfolio.
I hope this makes sense. :-)
-Mirko
 
Vladan Radovanovic
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actaully I am familiar with MVC and I just want a simple example how it is related to Servlets, JSPs and JavaBeans.
Thanks
Vladan
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual association of MVC to servlets, JSP and beans is:
JSP = View
Servlet = Controller
Beans = Model
In this approach, JSPs should contain mostly formatting, with (if necessary) a small amount of data access from the Model (beans) to show the data in an appropriate format. The Beans should be a complete data model, but contain no View or Controller code (so no "getAsHTML" type methods). The Controller part of MVC is always the hardest to pin down, but in this approach one or more servlets looks after workflow and program state, managing what information is stored in the context or session, which JSPs are displayed and what changes are made to the beans data model.
Has that helped?
 
Kagalkar Praveen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all
You can find an excellent example at the following link:
http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-forms.html
Praveen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic