Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help regarding a college project to be done using MVC pattern  RSS feed

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our last semester we did a project called "Library management system" using ASP.NET. It basically had users and a admin , where users can browse and book titles of the library. New books can be added , books can be deleted , modified and updated by the admin. The users can also change their personal details. The users can also view their books currently in use. We used Microsoft sql server.


Our teachers wanted us to do the same project using MVC pattern in J2EE.

So my idea of an MVC pattern is that the design should be in the JSP(the view) and all the major coding should be in servlets(the controller).

Have i interpreted it right?

What all suggestions can you give for the proposed project? Thanks in advance.
 
Junilu Lacar
Sheriff
Posts: 10948
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
achuthan mukundarajan wrote:So my idea of an MVC pattern is that the design should be in the JSP(the view) and all the major coding should be in servlets(the controller).

Have i interpreted it right?

Not quite right.

View: User interface and interaction, usually implemented using JSPs

Controller: receives requests, delegates work to the objects in the Model layer, gathers information that needs to be displayed back to the user, determines flow from one UI page to another. Can be implemented as servlets but can be Plain Old Java Objects (POJOs) if you use frameworks like Struts2 or Spring MVC. DO NOT, as you say, do the major coding in the servlets or any other controller class.

Model: Where most of your business logic should be coded

Note that there are also Infrastructure classes such as DAOs, Gateways (to web services, email, etc.) that you should keep separated from your main business logic.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Achuthan, I'll take your side. Junilu is being over-precise here, I think.

MVC is actually based on the concept of an entire tree of components, and often nodes in that tree are controllers linking Model and View components. In the case of frameworks such as JSF and Struts, the master controller is the Struts or FacesServlet. Someone has to, and in J2EE, the only other choice besides a servlet would be a JSP, which you have correctly noted, is better employed for making Views.

Note that in JSF2, the VIews are not JSPs, but special templates coded in a View Definition Language (VDL).

MVC in its purest form is somewhat worthless, since MVC only defines the View/Model interactions under the guidance of the Controllers. Practical web applications of course, need ways to populate and save Model values and apply business logic, and that's where the DAOs and business beans come in. There is no formal name or specification for those functions in the definition of MVC.
 
Junilu Lacar
Sheriff
Posts: 10948
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Achuthan, I'll take your side. Junilu is being over-precise here, I think.

I won't argue about being over-precise; it's just a habit I have from having to deal with a lot of problems that come from not being so. The point I wanted to make was that major coding should NOT be done in the controller servlets. The consequences of putting a lot of business logic in that layer is poor testability and poor separation of concerns. If you don't take care to avoid these problems when you're learning how to develop web apps, you will carry bad development habits over to professional work. That is not a good thing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!