I have an application of Shopping cart like in Profession JSP of wrox and I want to convert it by applying MVC Design Pattern to get it through. Would anybody of you all like to advise me the measures and design enable me to apply MVC for my application.
Actually, I asked a similar question a week or two ago in the servlets forum. You can find that discussion here. That discussion was based mostly on the servlet (controller) and model classes, but you might find it quite beneficial - I did. Hopefully, that will help get you started. If you have an initial design or some pressing questions before you get started, let me know and I'll help as much as I can. Otherwise, if you just need to know more about MVC, try here. If that's not enough, I'm sure Google would be useful. I hope that helps, Corey
Hi Ali, If it is possible to describe more abt your project, at least the architecture. With MVC u can have 2 approaches.. 1. jsp(view), servlet(as controller) and javabean(as model).pass the request from the jsp to the servlet, let the servlet do the buisness logic processing and all the db related stuf including the db connection can be put in a bean and that can be invoked by the servlet, after processing the servlet picks up a jsp page for display. 2. A full jsp-centric architecture where jsp(view)jsp(controller)and javabean(model) 3. A full servlet-centric architecture where a servlet(view) servlet(controller) and java classes/java bean as model. 4. An EJB centric architecture a) jsp(view)/servlet(controller and client to the EJB(Entity Bean..models data) b) jsp as client to the EntityBean U can make a decision based on the overall nature,no of users, data involved, transactions involved and take up any of the above approaches. Rishi Singh SCJP,SCWCD
posted 17 years ago
Originally posted by Rishi Singh: 1. jsp(view), servlet(as controller) and javabean(as model).pass the request from the jsp to the servlet, let the servlet do the buisness logic processing and all the db related stuf including the db connection can be put in a bean and that can be invoked by the servlet, after processing the servlet picks up a jsp page for display.
In general, when using such an architecture, I think you'd want to keep your business logic out of the servlet. If it's going to be the controller, that's all it should do. The business logic is better left in the model section. When it comes to things like database access (or any external system access, for that matter), classes for those should be abstracted to another layer for maintainability purposes. If you keep throwing things in the servlet, such as business logic, you'll soon find that it becomes difficult to extend the system through that servlet. I believe this will lead you to the "Magic servlet" antipattern that has been discussed here over the last couple days. Corey