Summary

In this chapter, you've seen how the Spring Framework allows you to develop a flexible and loosely coupled web-based application. Spring employs annotations for near-POJO development model in your web application. You learned that with Spring MVC, you can create a web-based application by developing controllers that handle requests, and these controllers are very easy to test. In this chapter, we covered the MVC pattern, including its origins and what problems it solves. The Spring Framework has implemented MVC patterns, which means that for any web application, there are three components--Model, View, and Controller.

Spring MVC implements the Application Controller and Front Controller patterns. Spring's dispatcher servlet (org.springframework.web.servlet.DispatcherServlet) works as a Front Controller in a web-based application. This dispatcher or front controller routes all requests to the application controller by using handler mapping. In Spring MVC, the controller classes have extremely flexible request handler methods. And these handler methods handle all the requests of a web application. There several ways, as we explained in this chapter, to handle request parameters. The @RequestParam annotation is one of the ways to handle request parameters, and it is also very easy to test without using the http request object in test cases.

In this chapter, we explored the request processing workflow, and discussed all the components which play a role in this workflow. The DispatcherServlet can be considered the main component in Spring MVC; it plays the role of a front controller in Spring MVC. Another main component is the view resolver, which has the responsibility to render the model data to any view template such JSP, Thymeleaf, FreeMarker, velocity, pdf, xml and so on depending om the configured view resolver in the web application. Spring MVC provides support for several view technologies, but, in this chapter, we briefly looked at how to write views for your controllers using JSPs. We can also add consistent layouts to your views using Apache tiles.

And finally, we covered the web application architecture, and discussed the different layers in a web application such as domain, user interface, web, service, and data access. We created a small bank management web application, and deployed it to the tomcat server.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset