org.springframework.web.servlet package
. It dispatches the request to the appropriate controller and manages the flow of the application. It is required to specify the DispatcherServlet class in the web.xml
file. xml
file or properties
file. In this file, we generally define the base-package and view resolver where DispatcherServlet
searches for the controller classes and view components path. However, it can also contain various other configuration properties. InternalResourceViewResolver
is a class which is used to resolve internal view in Spring MVC. Here, you can define the properties like prefix and suffix where prefix contains the location of view page and suffix contains the extension of view page.<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
ModelMap
has a similar purpose, with the ability to pass a collection of values. It then treats those values as if they were within a Map. We should note that in Model (ModelMap
) we can only store data. We put data in and return a view name.ModelAndView
, we return the object itself. We set all the required information, like the data and the view name, in the object we're returning.