简体   繁体   English

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

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

I run a springmvc and velocity demo and meet the problem that Could not resolve view with name 'index'(controll to index.vm) and below is my project configuration: 我运行了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 

below is my velocity configuration in applicationContext-servlet.xml 下面是我在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> 

and below is my web.xml 下面是我的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> 

my controll code is like that: 我的控制代码是这样的:

 @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"; } } 

when I run on tomcat I meet the problem that can't reach index.vm,is there any thing wrong in xml configuration ,thanks! 当我在tomcat上运行时,遇到无法到达index.vm的问题,在xml配置中是否有任何错误,谢谢!

In applicationContext-servlet.xml change 在applicationContext-servlet.xml中更改

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

to

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

I changed 我变了

<property name="resourceLoaderPath" value="/WEB-INF/views/" /> to <property name="resourceLoaderPath" value="/" /> adn it works <property name="resourceLoaderPath" value="/WEB-INF/views/" /><property name="resourceLoaderPath" value="/" />

暂无
暂无

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

相关问题 javax.servlet.ServletException:无法解析名称为“ dispatcher”的servlet中名称为“ index.html”的视图 - javax.servlet.ServletException: Could not resolve view with name 'index.html' in servlet with name 'dispatcher' Java,Spring,Apache Tiles错误:无法解析名为&#39;dispatcher&#39;的servlet中名为&#39;index&#39;的视图 - Java, Spring, Apache Tiles error : Could not resolve view with name 'index' in servlet with name 'dispatcher' javax.servlet.ServletException:无法解析名称为“ dispatcher”的servlet中名称为“ home”的视图 - javax.servlet.ServletException: Could not resolve view with name 'home' in servlet with name 'dispatcher' Maven项目异常:javax.servlet.ServletException:无法解析名称为“ dispatcher”的servlet中名称为“ login”的视图 - Maven project exception : javax.servlet.ServletException: Could not resolve view with name 'login' in servlet with name 'dispatcher' Spring4 $ Tiles3集成:无法在名称为“ dispatcher”的servlet中解析名称为“ home”的视图 - Spring4 $ Tiles3 integration: Could not resolve view with name 'home' in servlet with name 'dispatcher' Spring Mvc Java无法解析名称为&#39;dispatcher&#39;的servlet中名称为&#39;home&#39;的视图 - Spring Mvc Java Could not resolve view with name 'home' in servlet with name 'dispatcher' javax.servlet.ServletException:无法解析名称为“ dispatcherServlet”的servlet中名称为“ forward:/ index”的视图 - javax.servlet.ServletException: Could not resolve view with name 'forward:/index' in servlet with name 'dispatcherServlet' 无法在名称为“ dispatcherServlet”的servlet中解析名称为“ forward:/index.html”的视图 - Could not resolve view with name 'forward:/index.html' in servlet with name 'dispatcherServlet' 我找不到无法解析名称为“DispatcherServlet”的 servlet 中名称为“index”的视图的答案 - I can't find answer that Could not resolve view with name 'index' in servlet with name 'DispatcherServlet' 无法解析名为&#39;spring&#39;的servlet中名为&#39;streamrecords&#39;的视图 - Could not resolve view with name 'streamrecords' in servlet with name 'spring'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM