class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix">
<value>.vm</value>
</property>
<property name="toolboxConfigLocation">
<value>/WEB-INF/toolbox.xml</value>
</property>
</bean>
2.toolbox.xml
<?xml version="1.0" encoding="UTF-8"?>
<toolbox>
<tool>
<key>import</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.ImportTool</class>
</tool>
<tool>
<key>tsu</key>
<scope>request</scope>
<class>mvc.ToStringTools</class>
</tool>
</toolbox>
3.vm中即可
<html>
<head>
<title>Course List</title>
</head>
<a href="http://www.baidu.com">$course</a><br><a href="http://www.baidu.com">$courseName</a>
<br><a href="http://www.baidu.com">$tsu.toString($course)</a>
----------------------------------
$import.read("/velocity/ttest1.vm"); //写法一
----------------------------------
$import.read("/aa.do"); //写法二
</body>
</html>
写法一:只能以静态文件的方式导入进来,源码中可以看到最后是通过RequestDispatcher 来实现导入的,原理和jsp的include很类似
RequestDispatcher rd = application.getRequestDispatcher(url);
rd.include(request, irw);
写法二:以请求的方式导入,相当于重新发起一个新的请求