org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'index.html'
 at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
 at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
 at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
 at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:317)
 at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:378)
 at service.HomepageService.updateIndex(HomepageService.java:52)
...

解决办法:加上下面这段即可

    String vmPath =ServletActionContext.getRequest().getSession().getServletContext().getRealPath("");
    Properties p = new Properties();
    p.setProperty("file.resource.loader.path", vmPath+"//");

    //初始化vm模板
    Velocity.init( p );
   Template template=Velocity.getTemplate("index.html","UTF-8");

相关文章:

  • 2021-11-29
  • 2021-09-29
  • 2021-06-23
  • 2021-07-20
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
猜你喜欢
  • 2022-01-04
  • 2022-02-10
  • 2021-09-17
  • 2021-10-01
  • 2021-11-30
  • 2021-07-31
相关资源
相似解决方案