Velocity使用VelocityLayoutServlet布局之ResourceNotFoundException异常的困扰

今天在学习使用Velocity的VelocityLayoutServlet布局的过程中遇到这样一个问题,请求的模板文件能够正常地加载显示,但是设置的默认的布局模板总是加载不了。

velocity.properties中我是这样配置的:

velocimacro.library=macros.vm
webapp.resource.loader.path=/WEB-INF/templates/
velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = false
velocimacro.permissions.allow.inline.local.scope = false
velocimacro.context.localscope = false
input.encoding=utf-8
output.encoding=utf-8
 
# Filepath for error template,
#  relative to web application root directory
tools.view.servlet.error.template = /WEB-INF/templates/layout/Error.vm
 
# Directory for layout templates,
#  relative to web application root directory
tools.view.servlet.layout.directory =/WEB-INF/templates/layout
 
# Filepath of the default layout template
#  relative to the layout directory
#  NOT relative to the root directory of the webapp!
tools.view.servlet.layout.default.template =mainTemplate.vm

看了半天源码我才突然发现,是官方文档中的配置文件实例中的这句注释彻底误导了我:

# Directory for layout templates,
# relative to web application root directory  
tools.view.servlet.layout.directory =/WEB-INF/templates/layout
我真的因为是相对于网站的根目录了,原来是相对于:

webapp.resource.loader.path
果断把:

tools.view.servlet.layout.directory =/WEB-INF/templates/layout

改为:

tools.view.servlet.layout.directory =/layout

问题就解决了,由于 这个配置的默认配置就是layout,所以直接注释掉也可以


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值