繁体   English   中英

带有速度的springmvc:无法在名称为“ dispatcher”的servlet中解析名称为“ index”的视图

[英]springmvc with velocity:Could not resolve view with name 'index' in servlet with name 'dispatcher'

我运行了springmvc和velocity演示,并遇到了无法解析名称为“ index”(控件为index.vm)的视图的问题,以下是我的项目配置:

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

下面是我在applicationContext-servlet.xml中的速度配置

  <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/WEB-INF/views/" /> <property name="velocityProperties"> <props> <prop key="input.encoding">UTF-8</prop> <prop key="output.encoding">UTF-8</prop> </props> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="layoutUrl" value="/WEB-INF/layouts/layout.vm" /> <property name="suffix" value=".vm" /> <property name="contentType"><value>text/html;charset=UTF-8</value></property> </bean> 

下面是我的web.xml

  <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext-servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

我的控制代码是这样的:

 @Controller public class ArticleController { @Autowired private ArticleService articleService; @RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET) public String welcomePage(Model model) { List<Article> list = articleService.getArticles(); model.addAttribute("departments", list); return "index"; } } 

当我在tomcat上运行时,遇到无法到达index.vm的问题,在xml配置中是否有任何错误,谢谢!

在applicationContext-servlet.xml中更改

    <property name="prefix" value="/WEB-INF/views/" />  

   <property name="prefix" value="/WEB-INF/velocity/views/" />  

我变了

<property name="resourceLoaderPath" value="/WEB-INF/views/" /><property name="resourceLoaderPath" value="/" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM