首页 > springmvc配置velocity报错

springmvc配置velocity报错

环境spring3.2,velocity1.7;

springmvc跳转到index.vm报如下错误:

Could not resolve view with name 'index' in servlet with name 'dispatcher'

WEB-INF的目录结构如下,index.vm放在WEB-INF/velocity/views文件夹下面

└─WEB-INF
    │  applicationContent-servlet.xml
    │  velocity.properties
    │  web.xml
    │
    └─velocity
        ├─fragments
        │      _footer.vm
        │      _header.vm
        │
        ├─layouts
        │      layout.vm
        │
        └─views
                index.vm

applicationContent-servlet.xml中关于velocity的配置如下:

 <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">  
         <!-- velocity模板路径 -->  
        <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>  

        <!-- velocity配置文件路径 -->  
        <property name="configLocation" value="/WEB-INF/velocity.properties"/>  
    </bean>   

   <bean id="viewResolver"
       class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
       <property name="cache" value="true" />
       <property name="prefix" value="" />
       <property name="layoutUrl" value="/WEB-INF/velocity/layouts/layout.vm" />
       <property name="suffix" value=".vm" />
       <property name="toolboxConfigLocation"
        value="/WEB-INF/velocity-toolbox.xml" />
   </bean> 

Controller中跳转的部分如下:

@RequestMapping(value="/welcome")  
    public ModelAndView helloVm(){  
    ModelAndView modelAndView=new ModelAndView();  
    modelAndView.setViewName("index");
  return modelAndView;  
 }  

启动项目访问 http://localhost:8080/mvc/welcome/就报index找不到,请问配置有什么问题吗?


 <property name="prefix" value="" />
       <property name="layoutUrl" value="/WEB-INF/velocity/layouts/layout.vm" />
       <property name="suffix" value=".vm" />

你这个prefix改成/WEB-INF/velocity/views/
试试。

【热门文章】
【热门文章】