This exercise is very advanced. This exercise is optional.
At the end of the hands-on exercises, you created a web application using an MVC architecture and a front controller.
You can read about the Front Controller pattern here:
There are many MVC frameworks. JavaServer Faces, as we will see next week, uses a Servlet called
javax.faces.webapp.FacesServlet. Spring uses a front controller Servlet called
Your challenge is to create your own simple MVC framework.
Your framework might help solve some (or all!) of the following common problems:
- Mapping a 'command' parameter to an appropriate class and/or method.
- Automatically selecting a view and forwarding control to the view after executing the command.
- Automatically setting the values of form parameters onto Java Beans in model classes
You can dynamically load and instantiate classes using
Class.forName("...").newInstance() and you can inspect/call methods of a class using the package
java.lang.reflect (or Apache Commons BeanUtils).
You might decide on a naming convention to automatically map from commands to view names.
Now that you've implemented your own framework, what are the reasons that you shouldn't do this in production code?