开发者

Spring MVC framework very basic Dispatcher question

When I'm looking at S开发者_如何转开发pring 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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜