This content has been marked as final. Show 3 replies
user10137999 wrote:You've probably misread that part.
I am Developing one MVC based web application using Servlets and JSP. I have red about MVC pattern that, there must be only one controller servlet which call all models or dao classes.
The usual advice is, for a given interaction, to keep business logic (e.g. invoking Model's business methods such as search, store, compute,...), and flow logic (go to this or that page according to the value of such or such value returned by the business logic) in the controller servlet, and leave the JSP do mere rendering (calling a getXxx method is generally OK there).
But Can I use more than one servlet as Controller class in my web application?Sure. Often a single servlet is used throughout a given flow (e.g. search train + select + pay, may all go through the same TrainBookingServlet , this latter doing the appropriate model calls according to the current step of the flow). But it's also entirely possible to have one servlet for each action SearchServlet , SelectSeatServlet, PayServlet .
Even with "one servlet serving all steps of a given flow", if you application has several flows (e.g. "book", but also "edit preferences", "Register Credit Card",...), it's probably a better idea (easier maintenance) to have different Servlets.
Because I am not using any Frameworks like Struts. Please suggest me good design for my application.You don't have to follow framework, especially if you're learning. However, keep in mind that the various existing frameworks:
- promote a consistent design approach (not consistent across frameworks, but within a given framework, and design consistency tremendously helps maintenance)
- have built-in or known solutions to recurring problems (performances, concurrency, handling the "back" button,...) that your ad-hoc solution may not address easily.
So once you have learnt (and got burnt :o) ), it may pay off to study the various frameworks and select one that fits most of your needs.