This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes am I using MVC correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "am I using MVC correctly?" Watch "am I using MVC correctly?" New topic
Author

am I using MVC correctly?

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
I am trying to determine if I am using the model-view-controller (MVC) pattern correctly. I have a web application which uses JSPs and JavaBeans (no EJBs). The user must login to the application. After doing so, 99% of the user's activity is read-only. That is, the user selects an item to view greater detail on and can see various levels of detail. The only user entry is for a few profile settings. I am not using servlets because I didn't want the address bar in the browser to display the long path and not be updated to the appropriate jsp page name. The only places that servlets should probably be used are when the user logs in and changes his profile settings.
All of my database connectivity is done in a single java bean class in my package. Each method of this java bean class (Service.java) accesses a different stored procedure in Sybase. The data from the stored procedure is returned to the calling JSP in a Vector, String, or another java bean. The JSP displays the data and relies on styles in a linked CSS file for the presentation. Some JSPs use tag libraries to help with the display. I am in the process of using the tag libraries through more places in the JSPs.
I would like to know if this is an acceptable manner of using MVC. My company is in the early stages of migrating to WebSphere Portal Server (WPS) and I've been told that WPS relies heavily on Struts. While investigating Struts, I've found that Struts relies heavily on MVC. I've been doing some reading on MVC but haven't found any concrete examples of how to implement MVC. Most of the articles just define what the MVC elements are.
Any hints at MVC and Struts are greatly appreciated. Thanks in advance.
By the way, I put this in the JSP forum because I couldn't find a portal forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Rather than looking for articles on MVC, do search for the term "Model 2". This is the term usually applied to the pattern used as an MVC approximation for web applications.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
From your write up, it seems to me you are using model 1 architecture where you delegate functionalities of you application to a bean. To use MVC model 2 which is widely advocated you have to have a controller which in most cases should be a servlet; hence there is the view just for the display and collection of data to and from the user, the model which is your bean and the controller which is your servlet(servlet controller) One book that addressed both models in details is Advanced Java Server Pages - David M. Geary.
I hope this helps.
Anselm Paulinus.
Charles Hasegawa
Ranch Hand

Joined: May 22, 2003
Posts: 117
So for my own clarification:
If you have a JSP page where a JavaBean is encapsulating the logic and the data this is Model 1 architecture.
If you have a JSP page where the JavaBean is supplied from a controller class (servlet, EJB, etc) this is Model 2 architecture.
Is that right?
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
The controller class is the class that takes control i.e. issues commands to the rest of the applications; it issues command to your EJB to open and get data from you database issues command or stores the data in a helper class or bean and issues command to the view i.e. JSP to display the data - reason why it is called control Servlet the session bean and entity bean of your EJB are not the controllers; you might have to Look for the text core J2EE patterns as well as other books on patterns to help with your designs. It is nice to start knowing this different patterns early in ones career as it helps in knowing why you are adopting a particular strategy over another.
 
Don't get me started about those stupid light bulbs.
 
subject: am I using MVC correctly?
 
Similar Threads
exact diff. or when to use :custom tags and useBeans.
Struts Training
Need some general help regarding MVC design.
This weeks giveaway
real project ... real problem (JSP or Servlet)