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 .
这是直接在我的工作文档粘帖过来的 懒了点 不过可以看得明白吧。。
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 .
这是直接在我的工作文档粘帖过来的 懒了点 不过可以看得明白吧。。