1.springmvc
<!--set up the View resolution tool - <BeanID= "Viewresolver"class= "Org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> < Propertyname= "suffix"value= ". VM"/> <!--Avoid garbled characters - < Propertyname= "ContentType"value= "Text/html;charset=utf-8"/> <!--<property name= "toolboxconfiglocation" value= "/web-inf/views/layout/toolbox.xml"/> - < Propertyname= "Datetoolattribute"value= "Datetool"/> < Propertyname= "Numbertoolattribute"value= "Numbertool"/> < Propertyname= "Exposerequestattributes"value= "true"/> < Propertyname= "Exposesessionattributes"value= "true"/> < Propertyname= "Layouturl"value= "LAYOUT/LAYOUT.VM"/> < Propertyname= "Order"value= "0"/> < Propertyname= "Toolboxconfiglocation"value= "/web-inf/views/layout/toolbox.xml" /> < Propertyname= "Viewclass"value= "Com.tanbao.common.VelocityToolbox20View" /> </Bean>
2.velocitytoolbox20view
Public classVelocitytoolbox20viewextendsVelocitylayoutview {@OverrideprotectedContext Createvelocitycontext (map<string, object> model, httpservletrequest request, HttpServletResponse ResponsethrowsException {Viewtoolcontext ctx; CTX=NewViewtoolcontext (Getvelocityengine (), request, Response, Getservletcontext ()); Ctx.putall (model); if( This. gettoolboxconfiglocation ()! =NULL) {Toolmanager TM=NewToolmanager (); Tm.setvelocityengine (Getvelocityengine ()); Tm.configure (Getservletcontext (). Getrealpath (Gettoolboxconfiglocation ())); if(Tm.gettoolboxfactory (). Hastools (Scope.request)) {Ctx.addtoolbox (Tm.gettoolboxfactory (). CreateToolbox (Scope.request)); } if(Tm.gettoolboxfactory (). Hastools (scope.application)) {Ctx.addtoolbox (Tm.gettoolboxfactory (). CreateToo Lbox (scope.application)); } if(Tm.gettoolboxfactory (). Hastools (scope.session)) {Ctx.addtoolbox (Tm.gettoolboxfactory (). CreateToolbox (scope.session)); } } returnCTX; }}
3.toolbox.xml
<?XML version= "1.0" encoding= "UTF-8"?><Tools><ToolboxScope= "Application"> <!--<tool key= "map" class= "Java.util.HashMap"/> - <ToolKey= "env"class= "Com.tanbao.common.EnvContext"/></Toolbox></Tools>
SPRINGMVC Velocity Toolbox Configuration