velocity 学习1 环境配置。

Start with velocity.

1.set the enviroment for velocity:

(1).New a web project in eclipse.
(2).Add the jars package to the project .you could find all the
jars package needed in jarsForVelocity package.
(3).Define the servlet for the velocity in the web.xml file :

<web-app>
<servlet>
<servlet-name>velocityView</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>velocityView</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
</web-app>

Now ,the velocityView will deal with all the *.vm url in
this project.the toolbox.xml define the module we could
use.
(4).New a file toolbox.xml in WEB-INF folder and edit it like this:

<?xml version="1.0"?>
<toolbox>
<tool>
<key>date</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<tool>
<key>math</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
</toolbox>
(5)Change the default page of this project in web.xml file :

<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>
(6).New a file index.vm :

#set($hello="Velocity")
<html>
<head>
<title>Hello</title>
</head>
<b>
Hello $hello World !
</b>
</html>
(7).Start the tomcat server and deploy this project ..you could
see "Hello Velocity World ! " in the page.

This is the Hello World for the velocity..Next step we will see
how to access the data .





这是直接在我的工作文档粘帖过来的 懒了点 不过可以看得明白吧。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值