想使用velocity的layout功能,自己尝试了下不太成功麻烦能帮我看下吗,我的模板文件layout.vm是下面
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>集成velocity</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=9" >
<link href="assets/css/bootstrap.css" rel="stylesheet" media="screen">
</head>
<body>
<div class="wrapper" style="position:relative;">
<!-- 页面头 -->
#include("common/header.vm")
<!-- content -->
$screen_content
<!-- 页面尾 -->
#include("common/footer.vm")
</body>
</html>
然后下面的展示页面hello.vm是下面
#set($layout = "common/layout.vm")
Hello Layout!
配置文件velocity.properties是下面
input.encoding=UTF-8
output.encoding=UTF-8
resource.loader=webapp
webapp.resource.loader.class=com.wonders.common.velocity.tools.WebappResourceLoader
webapp.resource.loader.path=/WEB-INF/cms/
# relative to web application root directory
tools.view.servlet.layout.directory = /WEB-INF/cms/common/
# relative to the layout directory
# NOT relative to the root directory of the webapp!
tools.view.servlet.layout.default.template = layout.vm
在web.xml里面配置了
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityLayoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
请问这样为什么跳转到hello.vm为什么不能装载模板文件呢,能请教下还需要怎么配置吗
ps.访问上面的hello.vm在浏览器只显示Hello Layout!,如果改成下面这样
#set($layout = "common/layout.vm")
$layout Hello Layout!
在浏览器输出common/layout.vm Hello Layout!