By Amar Sivas | | Updated : 2018-12-10 | Viewed : 308 times
In Servlet technology, after model preparation, need to add model to request and then redirect to JSP with request. So the model will be rendered in the JSP. But we no need to write code for above mentioned steps. Just we have to add response object and view name to the model. By configuring the ViewResolver, Model will be populated automatically in the view.
Spring MVC provided interfaces called ViewResolver and View, which are useful for deciding the view in which data model will be populated. Here ViewResolver contains the mapping between view name and view. So it will exact view with location then the model will be prepared as view and will be rendered in the browser.Please find the below given diagram for control flow.
After creation model object, the control’s responsibility is to display the data in the browser. But raw model cannot be used to display in the browser. So View or JSP will have to prepare html template by executing the logic. So controller need to send model to the View/JSP page. But controller does not know the view name and its location. Here View resolver will resolve name and location of that JSP. In the JSP page, the model will prepared as the html template. The prepared html template which contains the model will be populated in the browser through controller.
Spring provides different type of resolvers for deciding the view. After resolution, the model will be prepared as view and rendered in the browser.
AbstractCachingViewResolver: is an interface which will be used for caching certain views.
XmlViewResolver: will allows to define views in XML file. Spring will use XML configuration file to decide the view.
ResourceBundleViewResolver: will be used to configure views in resource bundle (properties file). Spring will use this file to resolve the views in which model will be rendered.
UrlBasedViewResolver: will allows direct resolution of view names to URL without explicit mapping.A defined symbolic name in controller class will be decided the view name with location.
InternalResourceViewResolver: this is convenient class for UrlBasedViewResolver for view configuration.
FreeMarkerViewResolver: is convenient subclass of UrlBasedViewResolver that supports FreeMarkerView
ContentNegotiatingViewResolver: resolves a view based on the request file name or Accept header.