Spring MVC framework is a very simple dispatcher question

When I look 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 does not work for me. Only when I change the code as follows:

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

It works great. Can someone tell me why?

+7
java spring spring-mvc
source share
1 answer

View names are permitted in the actual view of ViewResolver s.

To link to short JSP pages, you need to set the InternalResourceViewResolver using 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:

+9
source share

All Articles