Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC framework very basic Dispatcher question

When I'm looking at Spring FrameWork 3.0 I see the following code example:

@RequestMapping("/index.dlp")
public ModelAndView index(){
    logger.info("Return View");
    return new ModelAndView("index");
}

This option doesn't work for me. Only when I change the code the following way:

@RequestMapping("/index.dlp")
    public ModelAndView index(){
        logger.info("Return View");
        return new ModelAndView("index.jsp");
    }

It works fine. Can anybody tell me why?

like image 621
danny.lesnik Avatar asked Oct 11 '10 15:10

danny.lesnik


People also ask

What is the core problem that Spring MVC framework solves dispatcher servlet?

What Is the Core Problem That Spring MVC Framework Solves? Spring MVC Framework provides decoupled way of developing web applications. With simple concepts like Dispatcher Servlet, ModelAndView and View Resolver, it makes it easy to develop web applications.

What is dispatcher MVC?

Class Phalcon\Mvc\Dispatcher Dispatching is the process of taking the request object, extracting the module name, controller name, action name, and optional parameters contained in it, and then instantiating a controller and calling an action of that controller.

What is the relationship between a Spring controller and the dispatcher servlet?

In the case of Spring MVC, DispatcherServlet is the front controller. The DispatcherServlet's job is to send the request on to a Spring MVC controller. A controller is a Spring component that processes the request.


1 Answers

View names are resolved into the actual views by ViewResolvers.

To refer JSP pages by short names, you need to supply InternalResourceViewResolver with prefix and suffix. The following configuration maps index to /WEB-INF/jsp/index.jsp:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

See also:

  • 15.5 Resolving views
like image 172
axtavt Avatar answered Sep 25 '22 13:09

axtavt