velocity模板页

模板页:dafault.vm

<html>
    <body>
        it's a default page.
        <div style="border:solid 5px black;padding:20px;">
        $screen_content
        </div>
</body>
</html>

配置文件:velocity.properties

input.encoding=UTF-8
output.encoding=UTF-8
resource.loader = webapp  
webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader

tools.view.servlet.layout.default.template = default.vm
tools.view.servlet.error.template = error.vm
tools.view.servlet.layout.directory = /layout/
webapp.resource.loader.path=/WEB-INF/templates/
webapp.resource.loader.path=/
webapp.resource.loader.path=/WEB-INF/vm/

还有web.xml

<servlet>
        <servlet-name>velocityView</servlet-name>
        <servlet-class>org.apache.velocity.tools.view.VelocityLayoutServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>velocityView</servlet-name>
        <url-pattern>*.vm</url-pattern>
    </servlet-mapping>

 

调用模板显示页面:index.vm

#set($hello="Velocity")
<b>
    Welcome to $hello World11 !
</b>
posted @ 2012-11-06 10:43  爱吃猫的鱼~  阅读(266)  评论(0编辑  收藏  举报