I think you are greatly mistaken between Web framework and MVC (Model-View-Controller) design pattern. There is nothing I have created to say I have implemented MVC using basic JSP, and writing servlet controller.
You don't need a web framework to accomplish MVC. You guys have been too used to frameworks and have lose sight for the basic concepts of MVC.
Let me try demystify what is MVC as much as I could, just in case you are still confused.
Model is Data. It doesn't need to be Java beans, it doesn't need to be complicated data-types. It definitely doesn't need to be fetched from the database or any other external storage resources. Just a simple integer created within the controller is data and hence the model. Model doesn't need to acquire any form of methods as found in an OOP. It is a good to have, but not necessary.
View is a mechanism to render for the client. The most basic form of a View is a HTML page. But HTML page is static and it is one form it will exist on the client end, but nothing says a View must be a HTML page. It can be a file of any type from an Image(PNG/JPEG/TIFF/BMP/...) to an audio file, a XML file, a JSON file and even another script file for download. That's the View. For server side to generate the view, we attach the idea of a View to components that generate it. In the case of Java, the JSP is normally taken as a View. Java Server Pages(JSP) are by themselves also Servlets. By default, they are dynamically compiled from JSPs into servlets before been run by the servlet container(I will explain servlet container later), or in production environment, statically compiled upon servlet container startup.
Now comes Controller. Controller is the heart of the whole MVC. It performs all the orchestration with respect to the Web Application. There can be more than one controller in large web application design. Multiple controllers can shares Views or have their own dedicated Views. They can also share Models or generate their own. For those that got use to the idea of a Router in the web frameworks. This is a special form of controller. It passes web request control from one controller to another controller. It is normally not found natively in some other languages such as PHP which requires a dedicated web framework router to do that. But it Java, the servlet container does the job of a router pretty well, although Struts and Spring framework attempt to provide the router job with more sophistication and complexity.
You may read of a slightly more complicated Java MVC found at
http://www.java-programming.info/tutorial/pdf/csajsp2/14-MVC.pdf
But I can be simpler than that.
You just need the following
1) One JSP page
2) One Servlet
Done. It's MVC
I will try hands free write you a simple Hello World in MVC form
Code:
// ** HelloWorldController.java
// web.xml configured to map /helloworld to this servlet controller
// nowadays annotation can also be used
public class HelloWorldController extends HttpServlet {
public void goGet(HttpServletRequest req, HttpServletResponse resp) {
req.setAttribute("helloworldMsg", "Hello World");
getServletContext().getRequestDispatcher("/helloworldView").forward(req, resq);
}
}
// ** HelloWorldView.jsp
<html>
<body><%=${helloworldMsg}%></body>
</html>
Really MVC is that simple at its concept. Allow me to just explain a bit. The Controller is the servlet HelloWorldController.java. As the whole web application is running in a servlet container such as GlassFish(J2EE), Tomcat(J2SE), JBoss and so forth
Using XML(normally) configuration, you can map a web application path to the servlet controller in this case /helloworld
The servlet container will play the role of a Router since it route web requests. In this case, the first web request hit the servlet controller what happened ?
The Model is created. It is the simple HelloWorld message that is contained in an attribute called "helloworldMsg". The scope of this attribute only exist for this web request. When the web request lifecycle ends, the attribute vanishes into thin air.
How do I pass the Model to the View ? I uses the Request Dispatcher found in all servlet container under the Servlet Context. I request the RequestDispatcher to find me the JSP view, and since the attribute(Model) is already attached to the Request. The RequestDispatcher will hence pass this to the JSP view in which manner ? There are 2 ways to pass a request to another servlet, either forward or include. I don't want to explain too much, just say you can take forward like simulating another web request get initiated from the browser, except it doesn't and it is all happening within the servlet container. It is like a traffic police man ask you go back to the starting point and run your whole journey again, except one difference. You have a baggage now. The baggage is a piece of data (summon) given to you and you run the whole course again, but this time you are redirected to the Court instead of anywhere else.
The web request this time hit the HellowWorldView.jsp. The JSP is itself a very powerful template engine. Even if you don't use things like Velocity or HTMLTemplate or other forms of template engine, it can already be dynamically expressive.
Using JSP ETL, you can fetch attributes from various scopes in a certain order. Eventually the web scope is traversed and the "helloworldMsg" attribute is fetched and rendered into the HTML output.
The HTML output is then returned back to the browser, escape from the servlet container and get rendered on your display.
I hope the explanation of MVC is clear enough. So clearly there is nothing for me to create. It's all there from day One.
Using multiple PHP pages, multiple Perl pages or with the use of ModPerl in Apache, internal redirection can be easily achieved to create MVC. The mode of redirecting internally is not the only option of MVC. you can use HTTP redirection, passing information via a POST form, a URL query string that requires the browse to perform as part of MVC. There is nothing in the MVC design pattern that dictate the whole involvement must exclude the User Agent, in this case the browser.