I’m working on a dynamic website in Java and I’m interested in sticking with the MVC pattern.
What is the best way to divide the work of a webapp between JSP and Servlets?
Should I see my JSP file as the view of the program and the Servlet more as the controller?
If I should use the Servlet as a controller, is it wise to give a Servlet more than one functionallity, for example: send in an action number to the Servlet and the Servlet will switch case on it to decide which action to do. This way i can create very few Servlets and each one would be in charge of a separate type of requests.
Yes. JSPs are best used for implementing views.
Depending on your application requirements, there may be other views that are not implemented as JSPs. But your proposed division of responsibility is a good starting point.
This is more debatable. You can either have a small number of servlets and switch inside the servlet or have a large number of servlets and switch in the
"web.xml"file or in some framework classes. For instance, a lot of people use a restlet framework, and / or annotations to manage the dispatching of requests to controller servlets.My general advice would be: