Speed ​​setting in tomcat web application. (Cookbook)

I was recently introduced to the Velocity project.

I wrote a template and ran it as a simple Java application.

Integration in my existing web project is not so simple.

Can someone provide a cookbook for integrating Velocity and Tomcat?

Thanks everyone!

+4
source share
2 answers

Tomcat - servlet container; You do not need to integrate Velocity with it, but rather with your application. How exactly this should be done depends on your application:

+3
source

An easy way is to define a VelocityViewServlet in web.xml

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

In the parameters velocity.properties

 #resource loaders resource.loader = production production.resource.loader.class = org.apache.velocity.tools.view.WebappResourceLoader 

Then put your template in the root of your web browser and access it from the web browser using its name as the URL. eg.

 http://localhost:8080/index.vm 
+3
source

All Articles