How does MVC1 differ from MVC2? Is JSF MVC2? I was told by an interviewer that JSP is MVC1. Is it true?
1 Answers
The right terms are "Model 1 MVC pattern" and "Model 2 MVC pattern".
In Java terms, Model 1 MVC pattern has the "view" and "controller" in the same place (e.g. a single JSP file with <jsp:useBean>
or scriptlets, or a single servlet with out.println()
writing HTML). Model 2 MVC pattern separates the "view" and "controller" physically. The JSP/Facelets page is the view and a servlet is the controller. This allows multiple views to make use of a single controller (according the front controller pattern). Note that when there's no means of a model (essentially a simple Javabean class holding the data which is created/manipulated by the controller and presented by the view), then there's also no means of a MVC pattern.
JSF is definitely Model 2 MVC. The controller is the FacesServlet
. JSP can be either Model 1 or Model 2, depending on the presence of a servlet as front controller and the JSP file being inaccessible/unusable without invoking the controller first. Our servlets wiki page contains solely Model 2 examples.