Mayank Sharma
Mayank Sharma

Reputation: 203

Functioning of ModelAndView class in spring mvc 3

This may sound really stupid but I am unable to understand the flow of Spring MVC in my project.

When I write the below mentioned code, what happens?

ModelAndView mav = new ModelAndView("paging");

I have a paging.jsp in my project but what happens, how does it flow?

Upvotes: 1

Views: 639

Answers (1)

jny
jny

Reputation: 8057

When you write in your method

    ModelAndView mav = new ModelAndView("paging");
    ...
    return mav;

you tell Spring that you return model and view with the name paging. In configuration you need to tell Spring how to resolve this name. In your case you could use UrlBasedViewResolver:

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

For more information check Spring reference: Resolving Views

Upvotes: 1

Related Questions