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.
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.
Joined: May 22, 2003
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?
Joined: Sep 05, 2003
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 J2EEpatterns 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.