[英]velocity template resource not found exception
发生异常:org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“ ResourceLoader1.vm”
我在/ WEB-INF / templates中有ResourceLoader1.vm,我坚持使用此功能,请帮助我。
Properties props = new Properties();
props.put("file.resource.loader.path", "/WEB-INF/templates");
Velocity.init(props);
VelocityContext context = new VelocityContext();
context.put("greetings", "Many Happy returns");
context.put("name", "Joseph");
Writer writer = new StringWriter();
Template template = Velocity.getTemplate("ResourceLoader1.vm");
template.merge(context, writer);
您应该将.vm模板相对于CLASSPATH。 更好的选择是将/ templates目录放在WEB-INF / classes下,丢失道具,并按以下方式获取它:
Template template = Velocity.getTemplate("templates/ResourceLoader1.vm");
似乎您正在Web应用程序中使用Velocity。 为此,最好使用专门为这种用法设计的VelocityViewServlet 。
与配置一起使用的FileResourceLoader
不了解Web服务器以及上下文和内容,因此,按照配置方式,它将在运行应用程序服务器的文件系统根目录中查找WEB-INF
文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.