在struts.xml里配置
<constant name="struts.velocity.toolboxlocation" value="/WEB-INF/toolbox.xml"></constant>
然后再WEB-INF/toolbox.xml 下面加上:toolbox.xml
<?xml version="1.0"?>
<toolbox>
<tool>
<key>link</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.StrutsLinkTool
</class>
</tool>
<tool>
<key>msg</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.MessageTool
</class>
</tool>
<tool>
<key>errors</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.ErrorsTool
</class>
</tool>
<tool>
<key>form</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.FormTool
</class>
</tool>
<tool>
<key>tiles</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.TilesTool
</class>
</tool>
<tool>
<key>validator</key>
<scope>request</scope>
<class>
org.apache.velocity.tools.struts.ValidatorTool
</class>
</tool>
</toolbox>
struts 与 velocity 整合以后,有哪些内置的变量可以直接用?
- req - the current HttpServletRequest
- res - the current HttpServletResponse
- stack - the current OgnlValueStack
- ognl - an instance of OgnlTool
- ui - a (now deprecated) instance of a ui tag renderer